gpt4 book ai didi

android - 写入文件.properties

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:08:18 24 4
gpt4 key购买 nike

我正在用 android 2.2 做一个应用程序,我在 Assets 文件夹中创建了一个文件 config.properties,我正在尝试使用以下代码修改属性:

AssetManager am = this.getResources().getAssets();
Properties pp = new Properties();

InputStream isConfig = am.open("config.properties",Context.MODE_PRIVATE);
pp.load(isConfig);

pp.setProperty("SHOP_URL", "NEW_SHOP_URL");//This key exists

try {
pp.store(new FileOutputStream("config.properties"), null);
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}

运行应用程序时,抛出这个错误:java.io.FileNoFoundException:只读文件系统。

我正在尝试添加权限来解决这个错误,但我不知道添加哪个。

感谢帮助

最佳答案

这里的问题是文件路径。尝试使用

try {
pp.store(getAssets().openFd("config.properties").createOutputStream(), null);
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}

这应该可以解决路径问题。

关于android - 写入文件.properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6725322/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com