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

看板java作者 (BMW 428i)時間4年前 (2020/01/24 03:02), 編輯推噓1(104)
留言5則, 2人參與, 4年前最新討論串1/2 (看更多)
我有一個文件*.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); } 就可以顯示文件全部的內容,但是請問這兩種方式在邏輯上好像 沒甚麼不一樣????請問為什麼會有這樣的狀況? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.228.249.225 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/java/M.1579806122.A.288.html

01/24 03:18, 4年前 , 1F
看一下你哪邊有用到readLine方法 用debug模式查就知道了
01/24 03:18, 1F

01/24 05:49, 4年前 , 2F
例1:while讀 print讀 while讀 print 讀 所以只
01/24 05:49, 2F

01/24 05:49, 4年前 , 3F
有雙數行印出
01/24 05:49, 3F

01/24 05:51, 4年前 , 4F
例2:while讀進str print已讀進str (loop)
01/24 05:51, 4F

01/24 05:54, 4年前 , 5F
就會每行印出
01/24 05:54, 5F
文章代碼(AID): #1UAUsgA8 (java)
文章代碼(AID): #1UAUsgA8 (java)