Hi, i was wondering what would be the best way of reading a single line from a text file?
For example, i have a file that contains the following data:
dog
cat
bird
deer

How can i read the 3rd line of the file? I was thinking that i would have to store each line in a array and just calling it by the number in that array.

The other question I had was, how can i print to the end of a text file? without disturbing the text data that is already there?

Thanks in advance, Guy Od

>I was thinking that i would have to store each line in a array and
>just calling it by the number in that array.

Storing the data/lines which won't be used has little meaning; you can just read lines and keep skipping them until you read the line you require [i.e. to get the 3rd line, read and skip the first two]. If the file has a fixed format, e.g. only 20 characters per line and '\n' used as the line separator, you can use the seek method to skip the calculated number of bytes and directly move to the data in consideration.

>how can i print to the end of a text file?

If by `print' you meant `write', you can open the file in append mode. If by `print' you meant display the data, then it shouldn't be a problem considering that you are using a Reader to read your file data.

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.