DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Reading from a file (http://www.daniweb.com/forums/thread88978.html)

KimJack Sep 8th, 2007 1:03 pm
Reading from a file
 
Hello All,

I am trying to figure the best route to take for this problem. I am trying to read from a text file. The text file is setup at follows:

John 90 98 9009
Smith 90 87 87987
Eric 76 66 23443...

I am trying the figure how to read only the names from the files. I cannot use String tokenizer or split().

I have tried everything that I can think of. Right now I can read the entire line.

No code please, only suggestions and comments.

Thank you,

peter_budo Sep 8th, 2007 2:53 pm
Re: Reading from a file
 
Once you read the line, look for position of empty space in your string from beginning and then substring it. String method charAt(num) and substring(int beginIndex, int endIndex) will help you.
Second option is to use Serialization because you know how the text is formated (meaning text followed by number separated by one empty space)

KimJack Sep 8th, 2007 4:00 pm
Re: Reading from a file
 
Thanks.

I am wondering if it is possible to read the first column of the text file into an array or arraylist?

peter_budo Sep 8th, 2007 5:01 pm
Re: Reading from a file
 
Yes, if you use second approach and simply ignore numerical content after empty character


All times are GMT -4. The time now is 10:33 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC