• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

reading from file an expression

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i have a file "*.txt" that contains a lot of informations seperated by ";"
i wanted just to read the second and the third argument.can you please help me doing that?
this is my code that allows me to read text file


how can i read only the 2nd and the third argument from this file??


thank you
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your information is separated by ";"
Read line
Split (hint) the string using the ";" delimiter
Process required information
 
Ranch Hand
Posts: 49
1
Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use StringTokenizer and then read 2nd, 3rd items from resultant array
or simply use sub string, index of methods from String class to read 2md, 3rd fields

P.S: kind of repeated what Maneesh said :-)
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

krishna kanth wrote:You can use StringTokenizer...


You can, but I'd suggest you don't. StringTokenizer is a legacy class, which has been superceded by Scanner (java.util.Scanner).

However, you don't even need that. You already have what looks like perfectly good code for processing lines, so just do what Maneesh suggested for each line (even bigger hint than he gave: look at String.split() ).

Winston
 
reply
    Bookmark Topic Watch Topic
  • New Topic