RSS Forums RSS

Reading from a file

Please support our Java advertiser: Programming Forums
Reply
Posts: 97
Reputation: KimJack is an unknown quantity at this point 
Solved Threads: 0
KimJack KimJack is offline Offline
Junior Poster in Training

Question Reading from a file

  #1  
Sep 8th, 2007
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,
Last edited by KimJack : Sep 8th, 2007 at 12:04 pm. Reason: forgot something
AddThis Social Bookmark Button
Reply With Quote  
Posts: 3,465
Reputation: peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold 
Solved Threads: 412
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Reading from a file

  #2  
Sep 8th, 2007
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)
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote  
Posts: 97
Reputation: KimJack is an unknown quantity at this point 
Solved Threads: 0
KimJack KimJack is offline Offline
Junior Poster in Training

Re: Reading from a file

  #3  
Sep 8th, 2007
Thanks.

I am wondering if it is possible to read the first column of the text file into an array or arraylist?
Reply With Quote  
Posts: 3,465
Reputation: peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold 
Solved Threads: 412
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Reading from a file

  #4  
Sep 8th, 2007
Yes, if you use second approach and simply ignore numerical content after empty character
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 805 | Replies: 3 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:51 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC