Extract field from text file

Reply

Join Date: Apr 2006
Posts: 114
Reputation: KimJack is an unknown quantity at this point 
Solved Threads: 0
KimJack KimJack is offline Offline
Junior Poster

Extract field from text file

 
0
  #1
Sep 9th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,190
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 483
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Extract field from text file

 
0
  #2
Sep 9th, 2007
Serialilzation is solution to your question. Try to read this tutorial from Java How to Program
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 114
Reputation: KimJack is an unknown quantity at this point 
Solved Threads: 0
KimJack KimJack is offline Offline
Junior Poster

Re: Extract field from text file

 
0
  #3
Sep 9th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,438
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Extract field from text file

 
0
  #4
Sep 10th, 2007
I can't see why you need to avoid split, but Scanner and java.util.regex are other options for parsing your input.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 114
Reputation: KimJack is an unknown quantity at this point 
Solved Threads: 0
KimJack KimJack is offline Offline
Junior Poster

Re: Extract field from text file

 
0
  #5
Sep 10th, 2007
Thanks so much. This is a big help.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Extract field from text file

 
0
  #6
Sep 10th, 2007
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()?
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 164
Reputation: orko is an unknown quantity at this point 
Solved Threads: 10
orko orko is offline Offline
Junior Poster

Re: Extract field from text file

 
0
  #7
Sep 10th, 2007
you can use FileReader... here is the documentation for j2se 5: http://java.sun.com/j2se/1.5.0/docs/...ileReader.html
A Perfect World
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,610
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Extract field from text file

 
0
  #8
Sep 16th, 2007
> 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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC