【发布时间】:2014-08-26 19:28:12
【问题描述】:
我正在尝试在 Android 应用程序中加载保存在我的属性文件中的一些数据。
我已将我的属性文件放在 src 文件夹下。每次我尝试从我的文件中加载数据时,它总是告诉我 FileNotFoundException open failed ENOENT (No such file or directory)。
我的代码如下:
这段代码是保存文件(新建)
File file = new File("src/com/example/testphonegap/SilverAngel.properties");
FileOutputStream fileOut = new FileOutputStream(file);
properties.store(fileOut, "Properties");
fileOut.close();
这段代码是用来加载数据的
properties = new Properties();
InputStream is = null;
// First try loading from the current directory
try {
File f = new File("src/com/example/testphonegap/SilverAngel.properties");
is = new FileInputStream(f);
// Try loading properties from the file (if found)
properties.load(is);
GetPersonaliseSettings();
GetUserSettings();
GetFavSettings();
}
catch ( Exception e ) {
is = null;
}
你能告诉我我做错了什么吗?是文件的保存位置还是我的代码中缺少某些内容?
【问题讨论】:
-
您是否尝试将目录更改为外部位置,例如外部存储器中的新文件夹
-
不。请问我该怎么做
-
文件 f = new File(getApplicationContext().getFilesDir()+"/YourFolderName");
-
将该文件放在 projectDirectory/res/raw 中,而不是 src。
标签: java android properties filenotfoundexception