如何在java(Android)中编辑.property文件夹
我正在开发一个应用程序,将服务器URL和数据库名称保存在该文件中。我可以使用此方法从该文件成功访问该数据如何在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
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