This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading from file an expression

 
Haythem Ben Yahia
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your information is separated by ";"
Read line
Split (hint) the string using the ";" delimiter
Process required information
 
Krishna Kanth
Ranch Hand
Posts: 49
1
Chrome Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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 :-)
 
Winston Gutkowski
Bartender
Pie
Posts: 10217
58
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic