BufferedReader Method to Read Next Line??

K

Krmathieu

I am working on an application that creates a buffer from a random access file
using the BufferedReader class. I have been able to create the buffer from the
input file and read/then print the first line from the buffer by using the
BufferedReader class method of readLine(). However, I can not find a method
that would enable me to read in the next line. I have included the relevant
code from my app below:

fileName = fileChooser.getSelectedFile();
input = new RandomAccessFile( fileName, "r" );
fileReader = new FileReader( fileName.getName() );
bufferedReader = new BufferedReader ( fileReader );
String line = bufferedReader.readLine();

Does anybody know what method or code could be used to access the next line
of the buffer? Basically, what I am trying to do is read in each individual
line of a file, assign the line to a string variable and then check to see if
the string contains the start of a valid subject. Also, I tried resetting the
starting mark of the read from the buffer by using the reset() method of the
BufferedClass, but I got a compile error stating that the compiler could not
resolve the symbol of reset() even though I have included java.io.* as an
import statement. Any help that anybody could provide would be greatly
appreciated. Thanks.

Kevin
 
M

Michael Wong

Krmathieu said:
Does anybody know what method or code could be used to access the next
line
of the buffer? Basically, what I am trying to do is read in each
individual


When working with streams, the current position is the next character that
hasn't been read yet... unless you use the mark/reset methods, which allow
you to set a mark in the stream and reset the position back to that mark.
In your case (BufferedReader), just keep calling the readLine method, it
will return the next line of text. If the readLine method returns null,
you've reached the end of the stream.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top