I am writing a compiler program to read a text file. Some of the commands in the text file will tell me to skip back to a certain line in the text file and read from there. As things are, this code I have reads one line at a time until the end of the document. Is there anyway to have a parser skip back or forward to a certain line in the text file? Let us say for example I am currently on line 8 and the instruction is to go back and read line 4?
Here is my code for parsing the file.
try {
FileInputStream fstream = new FileInputStream("compilers.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
while ((strLine = br.readLine()) != null && checker == false) {
// rest of code in here
}
in.close();
}
You could do this with a
MapKey is your line number and value is your line. So you can get the line by line number when you required.