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,

Re: Extract field from text file 80 80

Serialilzation is solution to your question. Try to read this tutorial from Java How to Program

Re: Extract field from text file 80 80

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

Re: Extract field from text file 80 80

I can't see why you need to avoid split, but Scanner and java.util.regex are other options for parsing your input.

Re: Extract field from text file 80 80

Thanks so much. This is a big help.

Re: Extract field from text file 80 80

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()?

Re: Extract field from text file 80 80

you can use FileReader... here is the documentation for j2se 5: http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileReader.html

Re: Extract field from text file 80 80

> 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.