将数据写入 assets 目录下的 .properties 文件

Write data to .properties file in assets directiry

我的资产文件夹中有 "config.properties",我尝试获取数据并将数据写入该文件。当我尝试获取数据时 (getProperty()) - 一切正常,但是何时写入 (setProperty()) - 我在我的日志中得到 "java.io.IOException: write failed: EBADF (Bad file descriptor)" 并且我的 "config.properties" 中的数据没有改变。 这是我的 class:

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();
    }
}
}

I have "config.properties" in my assets folder and I try to get and write data to this file

那是不可能的。您可以在运行时读取资产,但不能修改它们。