對不起,嗯..深奧的標題,但這是我的問題? 如果我有一個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