不算乱码吧,只是把中文转为了 unicode 进行存储而已
解决方案 »
- android图片的抠图,求思路,求想法
- Service中的onRebind()方法到底什么时候被调用!
- Android-camera
- 跪求android nes模拟器源码
- 关于viewport设置求教
- Android中耳机功能Handset怎么实现
- 帮忙看一下报错log信息
- 如何实现GirdView点击略缩图跳转到新的activity显示大图(在imageview中)
- contentprivoder共享的问题
- 求助!使用Cocos2d-android 实现悬浮窗问题
- make all Cannot run program "make": Launching failed
- 新手求助adt更新问题
int i = 0;
if (!key && i < string.length() && string.charAt(i) == ' ') {
buffer.append("\\ ");
i++;
} for (; i < string.length(); i++) {
char ch = string.charAt(i);
switch (ch) {
case '\t':
buffer.append("\\t");
break;
case '\n':
buffer.append("\\n");
break;
case '\f':
buffer.append("\\f");
break;
case '\r':
buffer.append("\\r");
break;
default:
if ("\\#!=:".indexOf(ch) >= 0 || (key && ch == ' ')) {
buffer.append('\\');
}
if (ch >= ' ' && ch <= '~') {
buffer.append(ch);
} else {
String hex = Integer.toHexString(ch);
buffer.append("\\u");
for (int j = 0; j < 4 - hex.length(); j++) {
buffer.append("0");
}
buffer.append(hex);
}
}
}
}
你是想自己解析Properties生成的文件吗?那倒不如用json作为文件格式了。
try {
FileOutputStream s = new FileOutputStream(file, false);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s, "utf-8"));
//在这里手动遍历属性和值进行输出
s.close();
} catch (Exception e){
e.printStackTrace();
}
}但是如果这样输出的话,你再使用Properties进行读取加载,可能不能读到你想要的东西
因为这个东西要拿出来给别人用的。所以要显示中文的。
那用json格式很方便啊。
因为这个东西要拿出来给别人用的。所以要显示中文的。
那用json格式很方便啊。
json写到文件里面不是a=b这种格式
因为这个东西要拿出来给别人用的。所以要显示中文的。
那用json格式很方便啊。
json写到文件里面不是a=b这种格式
为什么一定要a=b的格式,直接用json就可以,现在没有那种主流语言不支持json吧。
如果你一定要用properties的格式,那就只能自己转一下了。直接用android类库是做不了了,因为properties把代码写死了。
同样的代码,在java上,不在android上运行,拿出文档来看就不是unicode编码的。public class test123 {
public static void main(String[] args) {
Properties prop = new Properties();
int issueType = 1;
int frequency = -1;
String description = "123131234124";
String contactInfo = "1234567";
prop.setProperty("IssueType", "呵呵");
prop.setProperty("Frequency", "12345");
prop.setProperty("Description", description);
prop.setProperty("ContactInfo", contactInfo);
saveConfig("c:/1.txt", prop); } static public void saveConfig(String file, Properties properties) {
try {
FileOutputStream s = new FileOutputStream(file, false);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s, "utf-8"));
properties.store(bw, "");
s.close();
} catch (Exception e){
e.printStackTrace();
}
}
}