Hi I'm trying modify an application to read in text files and collect pieces of data from them to use as input for an application. The data I need to collect from the individual files include doubles, int, and strings of varying lengths depending upon individual text files. There is a lot of content in the files that I do not need to read. My questions are
1) Is it best to use FileReader or FileWriter?
2) Is there any other way to skip complete lines other that Reader's skip(long n) method?
3) What methods should I use collect only the data that I need considering that I won't know the length of the ints, doubles, and strings I am trying to collect?

Thanks so much

Member Avatar for coil

1. FileReader. FileWriter, as the name implies, is probably for writing to a file.
2. Don't think so...
3. You can't, really, unless everything you need is in one group and you know where it starts and stops (e.g. if you know the information is from lines 1 to 18, then you can read the first 18 lines in a for loop and then stop reading). Otherwise, I don't think there is a way.

2). Skip might work IF all the records are exactly the same length.
Try it and see what happens.

Most of the text that I want to skip over is contained in the same lines. Is there anyway that I can skip unwanted lines and read only the ones of use to me?

If the lines in the file are all exactly the same length, then you can skip to any record. Multiply the record length by the desired number of records to skip.
If the lines are of different lengths, you need to read them one by one.

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.