【发布时间】:2014-05-22 20:12:44
【问题描述】:
我想在我的 android 应用中处理一个属性文件。属性文件位于主文件夹中,与其他 jar 文件位于文件夹中。我知道,这不是最好的。
代码:
InputStream propStream=MainActivity.class.getResourceAsStream("data.properties");
Log.d("propStreamOutput",propStream.toString());
File data = new File(propStream.toString());
Reader reader;
try {
reader = new FileReader(data);
dataProp = new Properties();
dataProp.load( reader );
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
所以,第 2 行的日志说: libcore.net.url.JarURLConnectionImpl$JarURLConnectionInputStream@421302e8
以这种形式 logcat 调用 System.err :
java.io.FileNotFoundException/libcore.net.url.JarURLConnectionImpl$JarURLConnectionInputStream@42097218: open failed: ENOENT (No such file or directory)
但是当我这样评论时:
InputStream propStream=MainActivity.class.getResourceAsStream("data.properties");
Log.d("propStreamOutput",propStream.toString());
File data = new File(propStream.toString());
// Reader reader;
// try {
// reader = new FileReader(data);
// dataProp = new Properties();
// dataProp.load( reader );
// } catch (FileNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
那么就没有 system.err 了!当然,第 2 行的日志调用也是如此。
【问题讨论】:
-
您认为
propStream.toString()会做什么? (提示:快速调试会告诉你)
标签: java android inputstream