对不起,嗯..深奥的标题,但这是我的问题? 如果我有一个BufferedReader
函数内,我可以逐行阅读,每次它读取一行,它读取上一次读取的行后,但考虑这一点:BufferedReader记忆功能之间的线
我有一个函数初始化BufferedReader
,从文件中读取几行文件,然后将BufferedReader
传递到另一个函数,然后从另一个函数中读取几行文件。假设文件包含10行,第一个函数读取6行,第二个函数读取4.
问题是什么时候BufferedReader作为参数传递给第二个函数,它会从头开始读取文件或者它将从第一个函数中的BufferedReader
中止位置开始。
BufferedReader br; //initialized somewhere
public void reada(){
for(int I=0; I<6; I++){
br.readLine();
}
//readb(br); Will calling this(and not the following line) read the first 4 or last 4 lines in a 10 line file?
//readc(); Will calling this(and not the above line) read the first 4 or last 4 lines in the same file?
}
public void readb(BufferedReader reader){
for(int j=0; j<4; j++){
reader.readLine();
}
}
public void readc(){
for(int k=0; k<4; k++){
br.readLine();
}
}
'“问题是什么时候BufferedReader作为参数传递给第二个函数,它会从文件的开始处开始读取文件,还是从BufferedReader在第一个函数中停止的地方开始。 ' - 这是很容易测试的,我建议你这样做:写一个小程序和**测试**它。 – 2015-01-27 01:30:26
当你尝试过时发生了什么?你有什么理由放弃它会神奇地倒带文件,并开始只是因为你把它传递给另一种方法? – EJP 2015-01-27 03:18:42