943,723 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 978
  • Java RSS
Sep 8th, 2007
0

Reading from a file

Expand Post »
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 1:04 pm. Reason: forgot something
Reputation Points: 8
Solved Threads: 0
Junior Poster
KimJack is offline Offline
114 posts
since Apr 2006
Sep 8th, 2007
0

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)
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
Sep 8th, 2007
0

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?
Reputation Points: 8
Solved Threads: 0
Junior Poster
KimJack is offline Offline
114 posts
since Apr 2006
Sep 8th, 2007
0

Re: Reading from a file

Yes, if you use second approach and simply ignore numerical content after empty character
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Jdbc...
Next Thread in Java Forum Timeline: I can't display the right output (else if statement)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC