首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java propertes 文件读取乱码有关问题

2012-11-20 
java propertes 文件读取乱码问题方法1使用native2ascii把中文转化为ascii码,这样读取的使用不会乱码。这种

java propertes 文件读取乱码问题

方法1

使用native2ascii 把中文转化为ascii码,这样读取的使用不会乱码。

这种方式不推荐。

方式2

Properties prop = new Properties();

prop.load(is);

关键是第二行代码,这里如果你传的是

?InputStream is= Test.class.getResourceAsStream(".sunline");

就会出现乱码。

如果你在包装一层。

InputStreamReader reader= new InputStreamReader(is);

把InputStreamReader 传给Properties ?

prop.load(reader);这样就不会乱码了。

?

因为InputStreamReader 是支持可以直接读取字符串的。?

?

so

public class PropertiesFactory {

public static Properties createProperties(InputStream is) {

Properties prop = new Properties();

InputStreamReader reader = new InputStreamReader(is);

try {

prop.load(reader);

return prop;

} catch (IOException e) {

e.printStackTrace();

}

return null;

}

}

?

?

热点排行