944,184 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3914
  • Java RSS
Sep 9th, 2007
0

Extract field from text file

Expand Post »
Hello all,

I wondering if anyone could tell me how to go about extracting a single field from a text file.

The file is all follows:

Jeff 8.00 8.9900 hadk
Kim 234.0 234 hak
Him 444.8 1.11 john...

How would I extract only the first column without using tokenizer or split?

Thank you,
Last edited by KimJack; Sep 9th, 2007 at 7:56 pm. Reason: error
Similar Threads
Reputation Points: 8
Solved Threads: 0
Junior Poster
KimJack is offline Offline
114 posts
since Apr 2006
Sep 9th, 2007
0

Re: Extract field from text file

Serialilzation is solution to your question. Try to read this tutorial from Java How to Program
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 875
Code tags enforcer
peter_budo is offline Offline
6,659 posts
since Dec 2004
Sep 9th, 2007
0

Re: Extract field from text file

I have never heard of serialization but I will read the tuturial and give it a try. In the mean time, would parsing a text file work? If so, how would I go about achieving the desired results?

Thanks
Reputation Points: 8
Solved Threads: 0
Junior Poster
KimJack is offline Offline
114 posts
since Apr 2006
Sep 10th, 2007
0

Re: Extract field from text file

I can't see why you need to avoid split, but Scanner and java.util.regex are other options for parsing your input.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Sep 10th, 2007
0

Re: Extract field from text file

Thanks so much. This is a big help.
Reputation Points: 8
Solved Threads: 0
Junior Poster
KimJack is offline Offline
114 posts
since Apr 2006
Sep 10th, 2007
0

Re: Extract field from text file

If you can't use split I doubt regex would be considered a viable alternative. It more or less does the same thing behind the scenes.

Maybe you should just google what other options you can use from the string class, such and find() and substring()?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Sep 10th, 2007
0

Re: Extract field from text file

you can use FileReader... here is the documentation for j2se 5: http://java.sun.com/j2se/1.5.0/docs/...ileReader.html
Reputation Points: 46
Solved Threads: 11
Junior Poster
orko is offline Offline
164 posts
since Apr 2006
Sep 16th, 2007
0

Re: Extract field from text file

> Serialilzation is solution to your question.
Serialization is a completely different beast. In serialization, you serialize i.e. persist an object onto the secondary storage and read them again as and when required. Here the user is presented with a simple text file so the only option is to read the file using the File streams or readers and parsing the content as required.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006

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: Help me with my wierd applet please.
Next Thread in Java Forum Timeline: connection mysql





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


Follow us on Twitter


© 2011 DaniWeb® LLC