Re: [問題] 存成Unicode (utf-8) 檔案
※ 引述《nimath ( 假 裝)》之銘言:
: 我要把 JTextArea 或 JTextField 裡的文字存成一個文字檔
: 但是文字檔要存成 utf-8 的格式
: 我試了好幾個方法可是都不太成功
: 程式截錄如下:
: Formatter output;
: output = new Formatter(filename);
: //方法一: 這個出來用utf-8看會約一半的字亂碼 一半正常
: output.format("%s\n", new String(textArea.getText().getBytes("utf-8")));
: //方法二: 這個出來的是big5碼
: output.format("%s",new String(textArea.getText().getBytes("utf-8"),"utf-8"));
: //方法三: 這個出來完全亂碼
: output.format("%s",newString(textArea.getText().getBytes("big5"),"utf-8"));
: //方法四: 這個出來的是big5碼
: output.format("%s",textArea.getText());
: 不知我是那個地方弄錯了
: 排列組合好多種寫法依舊無法把檔案存成 utf-8 的編碼
: 謝謝
試試看底下BufferedWriter
JTextField txt = new JTextField();
output = txt.getText();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter
(new FileOutputStream(filename),"UTF-8"));
bw.write(output);
bw.close();
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.143.207.118
→
02/25 23:44, , 1F
02/25 23:44, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 6 篇):