用Properties类如何向配置文件写入和读取中文呀? 读取中文要转一下码,从8859_1到GBK的转码写中文用properties类就不行,你可以先转成8859再写进去看看一般properties要用工具native2ascii转一下码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Properties prop = new Properties();prop.setProperty("name", new String("中文".getBytes("ISO-8859-1"), "GB2323"));是这样么?大虾。可写不进去呀:( 你需要首先关联到一个file上。read:Properties pro=new Properties();InputStream in=new FileInputStream("FileName");pro.load(in);in.close();write:Properties pro=new Properties();OutStream out=new FileOutputStream("FileName");prop.setProperty("name", new String("中文".getBytes("ISO-8859-1"), "GB2323"));pro.store(out,"header");in.close(); 多谢大虾。文件我关联了,写“GB2323”写不进去。只是这样时可以写入prop.setProperty("name", new String("中文".getBytes("ISO-8859-1"), "GBK"));但打开看中文被显示成“?” String content = new String((prop.getProperty("CONTENT").trim()).getBytes("ISO-8859-1"), "GB2323");是取出中文属性 to eci0(eci0) 大虾那么怎么将中文属性写进去呢?急急急!!!!! Properties pro=new Properties();pro.setProperty("中文key", "中文value");....OutputStreamWriter output;output = new OutputStreamWriter(new FileOutputStream("file name"), "encoding charset");pro.store(output, "title");InputStreamReader input;input = new InputStreamReader(new FileInputStream("file name"), "encoding charset");pro.load(input);pro.getProperty(..., ...); 对不起,上面写得好象不对,上面的方法是怎样让castor生成和读取xml文件。Properties 好像不用这么繁,它用的是system default encoding.然后,非ASCII字符会被save成:比如"桌面"就是\u684C\u9762 to hayai(生命树):pro.store(output, "title");不行呀。output只能是FileOutputStream类型。???? 阅读《Java核心开发技术从入门到精通》时,遇到的问题:这个语句是什么意思… 怎样显示菜单 excel问题 一个超级菜鸟的表白:我简直是颗白菜,连final都不懂,帮我啊! 求高手点拨一个“MyEclipse编辑Java代码的”“基功问题”。 关于乱码 帮忙解释一下这道程序!!!(在线等待) java 的运行问题 什么是线程棋啊,求大神解答!!! 多线程 JTable中如何实现表格项的数据验证功能,比如:第一个格子只能填10以下的数,第二个格子只能填20以下的数。。。 关于jdk的环境设置
prop.setProperty("name", new String("中文".getBytes("ISO-8859-1"), "GB2323"));
是这样么?大虾。
可写不进去呀:(
read:
Properties pro=new Properties();
InputStream in=new FileInputStream("FileName");
pro.load(in);
in.close();
write:
Properties pro=new Properties();
OutStream out=new FileOutputStream("FileName");
prop.setProperty("name", new String("中文".getBytes("ISO-8859-1"), "GB2323"));
pro.store(out,"header");
in.close();
只是这样时可以写入
prop.setProperty("name", new String("中文".getBytes("ISO-8859-1"), "GBK"));但打开看中文被显示成“?”
大虾那么怎么将中文属性写进去呢?
急急急!!!!!
pro.setProperty("中文key", "中文value");
....
OutputStreamWriter output;
output = new OutputStreamWriter(new FileOutputStream("file name"), "encoding charset");
pro.store(output, "title");InputStreamReader input;
input = new InputStreamReader(new FileInputStream("file name"), "encoding charset");
pro.load(input);
pro.getProperty(..., ...);
Properties 好像不用这么繁,它用的是system default encoding.然后,非ASCII字符会被save成:比如"桌面"就是\u684C\u9762
pro.store(output, "title");
不行呀。output只能是FileOutputStream类型。
????