作者qrtt1 (愚人)
站内java
标题Re: [问题] 存成Unicode (utf-8) 档案
时间Mon Feb 25 23:17:38 2008
※ 引述《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