my dog learned polymorphism*
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
Author

reading from file an expression

Haythem Ben Yahia
Greenhorn

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

Joined: Jul 26, 2007
Posts: 10523
    
    9

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
    
    1

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

Joined: Mar 17, 2011
Posts: 8241
    
  23

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

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reading from file an expression