aspose file tools
The moose likes Beginning Java and the fly likes reading from file an expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "reading from file an expression" Watch "reading from file an expression" New topic

reading from file an expression

Haythem Ben Yahia

Joined: Nov 29, 2012
Posts: 14
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

Joined: Jul 26, 2007
Posts: 10645

If your information is separated by ";"
Read line
Split (hint) the string using the ";" delimiter
Process required information

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Krishna Kanth
Ranch Hand

Joined: Oct 23, 2006
Posts: 49

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

Joined: Mar 17, 2011
Posts: 8626

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() ).


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
rocket mass heater kickstarter
subject: reading from file an expression