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,

Recommended Answers

All 7 Replies

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

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

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

Thanks so much. This is a big help.

Member Avatar for iamthwee

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

> 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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.