Help with how to count the number of tokens from the first line

Hi
I want to count the number of tokens from the first line of text, from my incoming file and print it out.
For example i have 12 tokens in the first line, so i want it to print out the number 12
my code is below
thanks
import java.io.*;
import java.util.*;
import java.lang.*;
import java.util.StringTokenizer.*;
import java.sql.*;
public class Data {
     public static void main(String[] args) {
                    String token = null;          
                    String currentToken = "";
                    Hashtable hh = new Hashtable();     
          try {
               Vector v2 = new Vector(100);
               Vector v = new Vector(100);
               FileReader file = new FileReader("words.txt");
               BufferedReader buff = new BufferedReader(file);
               String line = buff.readLine();
               StringTokenizer s = null;
               boolean eof = false;
               while  (!eof){
                    s = new StringTokenizer(line.trim(),",",true);
                    boolean lastToken = true;
               while (s.hasMoreTokens()) {
                          token = s.nextToken();
                              if (lastToken){
                               if (token.equals(",")) {
                                    v.add("");
                                           lastToken = false;
                                  if (! token.equals(",")) {
                               v.add(token);
                              else { if (currentToken.equals(",")) {
                                    v.add("");
                              currentToken = token;
                    if (token.equals(",")) {
                           v.add("");
               line = buff.readLine();
                    if (line == null){     
                         eof = true;}
               buff.close();
          }catch (FileNotFoundException fe) {     
                    System.out.println("Error - - " + fe.toString());
          }catch (NumberFormatException ne) {
                    System.out.println("Error - - " + ne.toString());
          } catch (IOException e) {
               System.out.println("Error - - " + e.toString());
}     2.

I can print out the amount of tokens from each line,
But i only want the first line to be counted, And i
also do not want the delimeters to be counted.
could you please give me some ideas?
Thanks
try
   BufferedReader br = new BufferedReader(new FileReader("item.kr"));
   while((str=br.readLine())!= null)
      itemslist.add(str);
catch(IOException ioe)
   System.out.println("Exception Occurred!!!");
}This snippet gets one Line from the item.kr file.
Then i would count (By useing a diffrent String Tokenizer) to count only this line!!!

Similar Messages

  • How to get customer number and name from the SD document

    Hi All,
    Can you please let me know how to get Customer Number and Name from the SD Document?
    Thanks a lot....
    Anil

    Hi,
    It will be displayed in the SD (BIlling document) itself,  you clikc on the VF03. The customer name and number will also appear in the SO document also Tcode VA03
    regards,
    radhika
    Edited by: kolipara radhika on Jul 10, 2009 5:32 AM

  • Help with how to save/export nave to DW from Fireworks

    Hola
    I have made my first menu in FW CS5 with rollovers and a drop down, that works beautiful (to me )
    My problem is when I save it, how can I save/export to DW?
    Should I go to file/export?
    Should I go to file/image preview?
    What about the rollover images?
    Which folder should I save them in?
    Direct to DW?
    I'm lost
    My site it's already upload (the first page)
    and the menu looks ok, everything works, but If I need to modify it, I got soooooo confuse, that
    I end up deleting everything and start from scratch (not good for my sanity)
    So, I would love some help please.
    I'm new at FW CS5 but I thing that its going to help me a lot
    Thanks
    Daniel Ulysses

    Hola Linda
    Thanks a lot, I'll try it.
    I made the menu bar in FW, (my first ever) and in FW, everything looks great
    even my drop down menu, but cannot find out how to save it.
    If I need to change something, then, nothing works.
    Thanks again
    Saludos
    Daniel Ulysses

  • Need help with how to store data in array in from reading file

    i have a file named xxx.txt
    i need to retreive data from that file. the data that i want to retrieve is enclosed with << >>
    temp xxx-123 ccc << 90.5>>
    haha xxx-563 sss 85.2
    after a few lines, the another record appear.
    temp2 xxx-123 ccc << 190.5>>
    haha2 xxx-563 sss 885.2
    i would like to record down the data, 90.5 & 190.5, how do i go about doing so, will appreciated it if someone would guide me along. thanks

    After you have read a line from the file either
    find the location of << and >> and substring the stuff in between or
    use regex (regular expression) however this is advanced and may be beyond your level of understanding.

  • I want to read lines from file, count it and extract numbers from a first line.

    i must do un loop?

    HI,
    i try to explain how to use to LABVIEW TOOLS...
    1. USE a for next loop
    2. here you must open the file with the VI. read lines from file.
    you can choos how many lines you read at same time.
    3. the string you can convert into an number.
    4. in the loop is the literal counter... this is you line couter....
    iun schrieb:
    > i must do un loop?

  • HT2729 NEED HELP? how do I transfer game to ipod from the computer

    Have downloaded games on my computer and GameStop said I could transfer them to the IPod but cant figure out how,
    Please help????

    Unless you downloaded them through iTunes, you can't. If you did, sync the iPod.
    (78554)

  • Can anyone help me with how to install itunes on windows 8.  The apple techs suggestions did not work

    Can anyone help me with how to install itunes on windows 8.  The apple techs suggestions didn't work.  Spent most of today installing and uninstalling itunes according to their instructions.  They will charge me again if I call again.

    When I run the iTunes64setup.exe it says: "The thingy is not a valid win32 application."
    That generally indicates that the installer has been getting damaged on the download.
    What web browser have you been using for downloading the iTunes64Setup.exe? Does it make any difference if you use Firefox instead of IE for the download (or vice versa)?

  • Hi, folks can some body help me¡  How  I can  use  de second  code  to  the  Itunes card  to  use  the  Itunes card.... My  number is vanished, how  i can submit  my  Itunes card?

    Hi, folks can some body help me¡  How  I can  use  de second  code  to  the  Itunes card  to  use  the  Itunes card.... My  number is vanished, how  i can submit  my  Itunes card?

    iTunes Store: Invalid, inactive, or illegible codes
    http://support.apple.com/kb/TS1292

  • I have an itouch, most songs i got off my cd's. i have a new laptop and want to put songs from itouch to laptop.I can only get the songs that i purchased onto the laptop? need help with how to get the rest from itouch to laptop please??

    i have an itouch, most songs i got off my cd's. i have a new laptop and want to put songs from itouch to laptop.I can only get the songs that i purchased onto the laptop? need help with how to get the rest of the songs (from my cd's) from itouch to laptop please??

    See this previous discussion:
    Recovering your iTunes library from your iPod or iOS device: Apple Support Communities

  • How to count the number of parameters from  consumer(ex.soapUI)?

    Hi,
    I am a beginner is OSB. I am working on a task that has to count the no.of .parameters from the consumer(Soap UI) in the proxy service. And if the parameter is lesser than 4 an error has to be thrown else it should be routed to another business service. Anyone worked on such scenario before?

    Thanks for the quick reply. I will explain the approach i followed, not sure whether it is correct or not.
    I haven't used any WSDL fiile , instead i used the xquery file.
    In the proxy service assign node i tried to catch the parameters using $inbound/ctx:transport/ctx:request/http:query-string/text() and assigned it to a variable.
    I have configured the assign node with the xquery file, here extracted the parameters using.
    declare function xf:parseRelativeURI($string1 as xs:string)
    as element(ns0:LNIGeneratorRequest) {
    <ns0:LNIGeneratorRequest>
              <ns0:numberofStampers>{xf:getParameter($string1,"numberofstampers=")}</ns0:numberofStampers>
                   <ns0:partitionId> {xf:getParameter($string1,"partitionid=")}</ns0:partitionId>
                   <ns0:type> {xf:getParameter($string1,"type=")}</ns0:type>
                   <ns0:clientInfo> {xf:getParameter($string1,"clientinfo=")}</ns0:clientInfo>
              </ns0:LNIGeneratorRequest>
    Then in the replace node i had replaced it with the "body" variable.
    All the conditions i had place in the xquery file. like below
    declare function xf:getParameterCount() as xs:integer{
    let $queryParams := xf:parseRelativeURI($string1)
    let $countParams := fn:count($queryParams/child::*)
    let $error := 0
    let $success := 1
    return if($countParams<10)
    then $error
    else $success
    Thanks in Advance

  • Help with looping and counting

    i am in a CS 1 class and need help with this loop
    /*Write a program that will allow the user to enter a character
              until the capital letter Z is entered
         The program should count the number of letters entered
              and print the total after the loop is completed*/
    here is what i have it doesn't end nor does it count and i don't know hwo to make it count also i suck at do..while loops hehe
    char b,Z=0;
              Scanner a = new Scanner(System.in);
         do
                   System.out.print("Enter a letter: "+"\n");
                   b=a.next().charAt(0);
              while (b !=Z);
    i know that its not even close to being right just help me out here
    Edited by: purplesmurf on Nov 14, 2008 7:25 PM

    The following program will count the number of chacters entered until Z is enetered.
    import java.io.*;
    class count
         public static void main(String[] args)throws IOException
              char ch;
              int cnt=0;
              DataInputStream br=new DataInputStream(System.in);
              do
              System.out.print("Enter a character:");
              ch=(char)br.read();
              if(ch!='Z')
                   cnt++;
              else
                   break;
              }while((ch=(char)br.read())!='Z');
              System.out.println("The Number of entered characters are:"+cnt);
    }

  • How to calculate the number of vowels from a txt file. Pls give me a hand!!

    Guys! How do i calculate the number of vowels from a txt file? I have to create a program to count the number of words, sentence, and vowels. So far I had managed to count the number of words. Now I need help on counting sentence and vowels! Pls give me a hand guys!

    I first have to read from the file not the string.I
    know how to read from a file. Now the problem ishow
    to compare a character from a txt file!You fail to understand, that you have read the data
    from the file into a string. Now loop over all
    characters in the string. Forget about the file.
    KajOr forget the scanners just as others have told you. Just read the file character by character using a FileReader.
    Kaj

  • How to know the number of children at the first visit of a view ?

    Hello,
    I'd like to make a modification to the JSF lifecycle so that when a view is first visited, it is possible to know the number of children before the RenderResponse phase.
    It seems that, following the RI source code, the dispatch method of the ExternalContext is called.
    This method calls itself the RequestDispatcher of the javax.servlet package.
    How can I do that ?
    Thanks in advance.
    bgOnline

    I've been here all the time, ever since I got my G4 and could finally OS X (started with 10.1.5). Don't know how ya coulda missed me.... I'm usually in the Using the OS Forum and the Finder forum, with occasionaly excursions in the Spotlight forum.
    BTW, so this isn't completely off topic, after getting frustrated by the file count and Finder displaying correct sizes I experimented with a couple of Applescripts but then found a wonderful little Contextual Menu item, CalculateSize:
    http://www.pixture.com/software/macosx.php
    It tells you not only the number of files and sub-folders in a given folder, it also tells you the number of invisibles of each and the total size of the items, and it calculates sizes ever so much faster than the Finder does.
    Francine
    Francine
    Schwieder

  • HT2729 I have limited space on my new ipad. How can I limit the number of songs from my itunes on my imac from going to my ipad when I connect the two?

    I have limited space on my new ipad. How can I limit the number of songs from my itunes on my imac from going to my ipad when I connect the two?

    you can do this by keeping the external hard drive connected and doing the following
    -hold shift key down on computer while opening iTunes and a prompt will appear to choose a library
    -select choose library, iTunes should bring up your explorer windows where you can search for the external HD
    -after you find the external HD find the iTunes folder you just copied to it
    -after opening the iTunes folder look for the file that says iTunes library.itl or if you can't see that extenstion just look for a document looking thing in the iTunes folder that shows up as a database file
    -double click the database file and boom iTunes should load your library without having to copy it to the computer
    PS: do make sure that if you are going to do it this way, make sure that the external HD is connected at all times, because if you don't then you will get exclamation marks next to your iTunes songs
    double PS: if you are unsure how to find out if the iTunes library file is a database file just right click it and choose properties and under the type it should say database file
    hope this helps:)

  • How, using Adobe Connect can increase the number of participants in the meeting? I need more than 25 people.

    Hi, I use licensed Adobe Connect. Earlier in the meeting could involve up to 100 people. Now only 25. How, using Adobe Connect can increase the number of participants in the meeting? I need more than 25 people.
    Thanks for your help.

    The purchasing option through adobe.com only allows up to 25 attendees. If you need more than that, you will need to purchase through a reseller. You can find one that is able to sell in your part of the world, here: Adobe Connect Partners. Just reach out to one of the Global Partners.

Maybe you are looking for

  • CAD Integration - Error While Saving file

    Hi, Im having One  Document type "DRW" which was working fine with all the functionalities. After that i created another document type "PDW". Now all the functionalities are working fine for this Document type and not for "DRW". Im getting an error w

  • Is there any way to shut off roaming but still use wifi?

    I am going on vacation to the States this week and I would still like to use my iPhone without getting charged lots for roaming. I'm only going to be using my phone for games and music, not calling or texting. I'd also like to check my emails every n

  • Compare 2 IDOCS for duplicate

    Hi, Please any one can help me to compare 2 IDOCS for duplication (all the data records only). Thanks in advance.

  • SB audigy 2 microphone problems when running fullscreened a

    Sounds odd, but here is the deal. Drivers works perfectly, nothing strange, thing is, im using Ventrilo(voice chat prog.) pretty much and here it comes: ?the other people cant hear me when im tabbed into a fullscreen game or any other fullscreen appl

  • Recommendation needed for duplicate clean-up and photostream settings

    Good day. We have 2 iphones and macbook and an iMac. The iMac is our main photo repository.  However, it has become overpopulated with photos. In iPhoto, I have the automatic import selected, so I have all kinds of duplicate photos now.  I also impor