1
我建一個性質/ RAW文件,當我看到文件,它是沒有問題的:如何在android的原始文件中編寫屬性文件?
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);