Reading a text file with integers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bambataa
    New Member
    • Mar 2007
    • 1

    Reading a text file with integers

    Hellloww...i am new to Java and i am facing a problem, i am reading a text file, i am using string tokenizer class,..now at some point when i read a first token i have to check it if its an integer then i should read the line, else i should go to the next line...how can i do this..
    thanx alot in advance
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    Originally posted by bambataa
    Hellloww...i am new to Java and i am facing a problem, i am reading a text file, i am using string tokenizer class,..now at some point when i read a first token i have to check it if its an integer then i should read the line, else i should go to the next line...how can i do this..
    thanx alot in advance
    you can use Integer.parseIn t() to parse a String for an integer
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Integer.html#pa rseInt(java.lan g.String)

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by bambataa
      Hellloww...i am new to Java and i am facing a problem, i am reading a text file, i am using string tokenizer class,..now at some point when i read a first token i have to check it if its an integer then i should read the line, else i should go to the next line...how can i do this..
      thanx alot in advance
      Do not use StringTokenizer . That class will probably be deprecated soon. Use the Scanner class to read the file.


      P. S I have renamed your thread.

      Comment

      Working...