1
I have a class that is responsible for reading a TXT file part by part and return me a result according to this part.
This result will be used by another class. That is, I open txt I read to a certain part and I re-turn to another class. However when I call this class it reads again. I want to pick up where I left off in txt and n have to read it all over again.
Example:
I have the following text file:
"Hi how are you? I would like to know your name
My name is Joao"
I want my reading class to read this part:
"Hi how are you? Like"
Then when you call her again she’ll start reading from here:
"would know his name
My name is Joao"
NOTE: This was just a hypothetical example.
Please help me. my code for reading is this:
FileReader in = null;
try {
in = new FileReader(dir);
BufferedReader br = new BufferedReader(in);
String line;
int lineNum = 1;
while ((line = br.readLine()) != null) {
verifyLine(line,lineNum);
lineNum++;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
The Verify function takes the line and reads only the parts I want. But when I give the Return I come back from the beginning. In other words, if I stay in this class I can read it the way I want to. But if I give Return to another class I already have problems.
Have you ever thought of Playing this text to a variable and deleting from it the part that has already been read ? Another option that came to mind was you have a parameter to inform from which position you should start reading, so just use the Content size that was returned +1 in this parameter, this option would serve ?
– Christiano Ribeiro Soares
Is the control done by line or by character? In your example you are cutting in the middle of the word, but the code seems to be reading line by line.
– Pablo Almeida
yes I can do the control via character and I think your Christiano solution can help me
– Lucas Alves