我在/raw 中构建了一个属性文件,当我读取文件时没有问题:
public static String readProperties(String filePath, String parameterKey) {
String result = null;
Properties pro = new Properties();
try {
pro.load(GlobalVariate.class.getResourceAsStream(filePath));
// pro.load(GlobalVariate.class
// .getResourceAsStream("/assets/config.properties"));
result = pro.get(parameterKey).toString();
} catch (IOException e) {
System.out.println("load fail:" + e);
e.printStackTrace();
}
return result;
}
但是当我写的时候说文件路径不存在:
public void saveConfig(Context context, String file, Properties properties) {
try {
FileOutputStream s = new FileOutputStream(file, false);
properties.store(s, "");
System.out.println("write success!");
} catch (Exception e) {
e.printStackTrace();
System.out.println("write error:+" + e);
}
}
saveConfig(this, "/assets/config.properties", prop);
最佳答案
您已经提到您想要将属性文件读写到/raw 文件夹中,但在这里您似乎正在将文件写入 assests 文件夹中。所以改变
/assests.config.properties
到
/raw/config.properties
关于android - 如何在android的原始文件中写入属性文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17467666/