[問題] printwriter寫不進檔案

看板java作者 (伏)時間11年前 (2012/12/07 17:49), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串1/1
板上各位神人好,想請教關於java printwriter的問題 程式用了Matrix,最後要輸出的時候發現東西沒寫進檔案 程式碼: File wt = new File("output.txt"); PrintWriter out = new PrintWriter(wt); Matrix result = Calculation.solve(a, b); result.print(out, 1, 4); 結果有產生output.txt,但是裡面沒有任何東西(程式有terminated) 但是如果我這樣寫 File wt = new File("output.txt"); PrintWriter out = new PrintWriter(wt); Matrix result = Calculation.solve(a, b); result.print(1, 4); 螢幕(stdout)上會正確顯現結果 確認過result.print的第一個參數要放printwriter 試過把wt的type改成Writer 或者直接用PrintWriter out = new PrintWriter("output.txt"); 但是結果還是一樣(可terminated但檔案沒內容),麻煩板上神人賜教,感激不盡!!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.25.108 ※ 編輯: jake080449 來自: 140.112.25.108 (12/07 17:51)

12/07 18:11, , 1F
flush & close 過了沒?
12/07 18:11, 1F

12/07 18:21, , 2F
你要是想關掉你就說話阿,你不說話我怎麼知道你想關掉 XD
12/07 18:21, 2F

12/10 11:35, , 3F
在最後補上out.close()就可以了~ 感謝一樓!!
12/10 11:35, 3F
文章代碼(AID): #1GmRkuVH (java)