Re: [問題] 存成Unicode (utf-8) 檔案

看板java作者 (愚人)時間18年前 (2008/02/25 23:17), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/6 (看更多)
※ 引述《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 的編碼 : 謝謝 沒寫過 Formatter, 不過您要不要先看一下預設的編碼是什麼? 說不定是您重複編碼了 for (Iterator it = System.getProperties().keySet().iterator(); it .hasNext();) { String key = (String) it.next(); if (key != null && key.contains("encoding")) { System.out.println(key + "=" + System.getProperties().get(key)); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.232.236.168
文章代碼(AID): #17mjmJCa (java)
討論串 (同標題文章)
文章代碼(AID): #17mjmJCa (java)