我的资产文件夹中有“config.properties”,我尝试获取数据并将其写入该文件。当我尝试获取数据(getProperty())时 - 一切正常,但是何时写入(setProperty()) - 我在日志和数据中收到“java.io.IOException:写入失败:EBADF(错误文件描述符)”在我的“config.properties”中没有改变。
这是我的课程:
class Property {
private static Properties properties = new Properties();
static String getProperty(String key, Context context) throws IOException {
AssetManager assetManager = context.getAssets();
InputStream inputStream = assetManager.open("config.properties");
properties.load(inputStream);
return properties.getProperty(key);
}
static void setProperty(String ipAddress, Context context) {
try {
properties.setProperty("ip_address", ipAddress);
properties.store(context.getAssets().openFd("config.properties").createOutputStream(), null);
}catch (Exception e){
e.printStackTrace();
}
}
}
我的资产文件夹中有“config.properties”,我尝试获取数据并将其写入该文件
这是不可能的。您可以在运行时读取资产,但无法修改它们。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)