Re: [問題]請問關於文件讀取行的問題!!!

作者: qrtt1 (有些事,有時候。。。)   2020-01-24 10:33:26
※ 引述《SST2000 (BMW 428i)》之銘言:
: 我有一個文件*.txt檔裡面內容是這樣
: In this below-sea-level basin, steady drought and record summer heat make
: Death Valley a
: land of extremes. Yet, each extreme has a striking contrast. Towering peaks
: are frosted with
: winter snow. Rare rainstorms bring vast fields of wildflowers. Lush oases
: harbor tiny fish
: and refuge for wildlife and humans. Despite its morbid name, a great
: diversity of life survives
: in Death Valley.
: 在程式碼裡面用
版友推文說得挺清楚了,
我只是把推文的內容展開一下
: while(bufferedReader.readLine() != null)
^^^^^^^^^^^^^^^^^^^^^^^^^
讀了一行出來 (但沒印) => 奇數行的情況
: {
: System.out.println(bufferedReader.readLine());
^^^^^^^^^^^^^^^^^^^^^^^^^
讀了一行出來,並印出來 ==> 偶數行的情況
: }
: 結果只會顯示第二行和第四行
: land of extremes. Yet, each extreme has a striking contrast. Towering peaks
: are frosted with
: and refuge for wildlife and humans. Despite its morbid name, a great
: diversity of life survives
: 但是如果用
: String str = null;
: while((str=bufferedReader.readLine()) != null)
: {
: System.out.println(str);
: }
: 就可以顯示文件全部的內容,但是請問這兩種方式在邏輯上好像
: 沒甚麼不一樣????請問為什麼會有這樣的狀況?

Links booklink

Contact Us: admin [ a t ] ucptt.com