File processing: Line Look-ahead

P

Prabh

Hi,
I'm traversing through an ASCII-text file line-by-line through
FileReader and LineNumberReader.
Each of the lines are processed for any match with a regular expression.
If match found, I need to print the "currentline + 1" line.

I'm using the while construct to loop through the file.
( str, lineReader, matcher match previously defined.)

while ((str = lineReader.readLine()) != null ) {
----
Regex processing
---
while ( match.find() ) {
Print the currentline + 1 here.
}
Could anyone give me some pointers, please.

Thanks,
Prabh
 
W

Wendy S

Prabh said:
Hi,
I'm traversing through an ASCII-text file line-by-line through
FileReader and LineNumberReader.
Each of the lines are processed for any match with a regular expression.
If match found, I need to print the "currentline + 1" line.

Read two lines before beginning the loop:

thisLine = read a line
nextLine = read a line

look for the match, print nextLine.

Then do:
thisLine = nextLine
nextLine = read a line

Be careful when you read the last line-- you may drop out of the loop, and
you'll still need to look for the match and possibly print out that final
line. What happens if the last line matches, and there is no next line?
 

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

No members online now.

Forum statistics

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

Latest Threads

Top