Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java(Android)中编辑.property文件夹_Java_Android - Fatal编程技术网

如何在java(Android)中编辑.property文件夹

如何在java(Android)中编辑.property文件夹,java,android,Java,Android,我正在开发一个应用程序,将服务器URL和数据库名称保存在该文件中。我可以使用此方法从该文件成功访问该数据 public static String getConfigValue(Context context, String name, String defaultValue) { Resources resources = context.getResources(); String propValue = defaultValue; try { In

我正在开发一个应用程序,将服务器URL和数据库名称保存在该文件中。我可以使用此方法从该文件成功访问该数据

public static String getConfigValue(Context context, String name, String defaultValue) {
    Resources resources = context.getResources();
    String propValue = defaultValue;

    try {
        InputStream rawResource = resources.openRawResource(R.raw.app);
        Properties properties = new Properties();
        properties.load(rawResource);
        File file = new File(Environment.getExternalStorageDirectory()+"/distribution/properties/app.properties");
        if(file.exists()){
            InputStream inputStream = new FileInputStream(file);
            properties.load(inputStream);
        }
        propValue = properties.getProperty(name);
    } catch (Exception e) {
        Logger log = LoggerFactory.getLogger(PropertiesLoader.class);
        log.error( "Unable to find the config file: ", e);
    }
    return propValue;
}
但是我想添加一个功能来编辑设置中的url,所以我添加了这个方法,但它不起作用

 public static Properties setConfigValue(Context context, String key, String value){
    Resources resources = context.getResources();

    try{
        InputStream rawResource = resources.openRawResource(R.raw.app);
        Properties properties = new Properties();
        properties.load(rawResource);
        File file = new File(Environment.getExternalStorageDirectory()+"/warehouse/properties/app.properties");
        if(file.exists()){
            InputStream inputStream = new FileInputStream(file);
            properties.load(inputStream);
        }
        properties.setProperty(key, value);
        OutputStream output = new FileOutputStream(context.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS)+ "properties/app.properties");
        properties.store(output, null);

        return properties;

    }catch(Exception e){
        Logger log = LoggerFactory.getLogger(PropertiesLoader.class);
        log.error("Unable to find the config file: ", e);
        return null;
    }
这是保存在
raw
文件夹中的我的
app.properties
文件夹

basicUrl =  url
serverDBName =  dbname