读书人

使用 Properties读取文件 为什么第一行

发布时间: 2012-05-13 16:39:43 作者: rapoo

使用 Properties读取文件 为什么第一行无法读取
InputStream inputStream=new BufferedInputStream(new FileInputStream("f://dbConfig.properties"));
properties.load(inputStream);
String str=new String(String.valueOf(properties.get("hibernateConfigPath")).getBytes("ISO-8859-1"),"UTF-8");
System.out.println(properties.get("tableNamePrefix"));
System.out.println(properties.get("dbType"));
System.out.println(properties.get("saveDataPath"));


文件里的第一行无法获得 不管怎么换 只要换到第一行了的 就无法获得 会显示null 这是什么原因、?

[解决办法]
神马意思?
LZ是说properties.get("hibernateConfigPath")这行取不到信息?
确定你的properties文件有hibernateConfigPath这个key吗?
[解决办法]
以前好像遇到过都是文件无法被加载的问题。就是确定下文件目录和文件是否正确。真的有这东西。
[解决办法]
不可能在第一行就读不到吧,写那么多程序,重来没遇到过
[解决办法]
1. debug一下,看看你的properties里面有什么
2. 检查你的第一行有没有隐藏字符;


[解决办法]
文件编码有问题吧?
如果用window的,直接用notepad打开此文件,看看如果是utf-8的转成ASCII
[解决办法]
String str=new String(String.valueOf(properties.get("hibernateConfigPath")).getBytes("ISO-8859-1"),"UTF-8");
System.out.println(properties.get("tableNamePrefix"));
System.out.println(properties.get("dbType"));
System.out.println(properties.get("saveDataPath"));
嘿嘿,是不是你就3个输出语句,所以只能看见3个结果,第一个str没输出的吗,

-_-
[解决办法]
应该是文件编码的问题,ascii的还是utf8的,utf8的是带bom的还是不带的


另外String str=new String(String.valueOf(properties.get("hibernateConfigPath")).getBytes("ISO-8859-1"),"UTF-8");的用法也是不好的,google一下“native2ascii”

读书人网 >Java相关

热点推荐