[問題] 關於JTextArea寫檔的問題

看板java作者 (沒)時間14年前 (2010/06/12 00:30), 編輯推噓5(505)
留言10則, 6人參與, 最新討論串1/1
請問一下各位版友 如果要將TextArea裡的所有字通通寫到某個txt檔中 我使用 BufferedWriter output = new BufferedWriter(new FileWriter(file)); output.write(textarea.getText()); 但是後來去看儲存結果 txt檔卻沒有換行 通通都擠在一行上 請問一下這要如何解決了? 謝謝版友們的回答 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.114.221.19

06/12 00:56, , 1F
加一行 output.newLine(); 就會換行了
06/12 00:56, 1F

06/12 02:04, , 2F
你用notepad開就會換行了 \n在txt不會換 會變空白
06/12 02:04, 2F

06/12 02:16, , 3F
1F:沒有用耶 2F:我想要在txt檔上看起來是換行的
06/12 02:16, 3F

06/12 02:59, , 4F
\r\n
06/12 02:59, 4F

06/12 07:34, , 5F
程式是不是在Linux跑的?然後在Windows下用notpad開啟?
06/12 07:34, 5F

06/12 09:07, , 6F
程式通通都是在windows下運作的 用記事本開的
06/12 09:07, 6F

06/12 11:24, , 7F
String str = textarea.getText.replace("\n","\r\n")
06/12 11:24, 7F

06/12 18:17, , 8F
tinyeclipse加油xd
06/12 18:17, 8F

06/12 18:21, , 9F
我同neigence getText().replaceAll("\n", "\r\n")
06/12 18:21, 9F

06/13 12:39, , 10F
哇!這篇釣到好多同班的
06/13 12:39, 10F
文章代碼(AID): #1C4cIJ83 (java)