2016-06-07 20 views
0

我有一個屬性文件存在於項目名稱/ properties/dev文件夾中。我在項目名稱/ src文件夾中編寫我的代碼。我想從Java代碼更新屬性文件。我無法獲取項目名稱/ src文件夾中的屬性文件的路徑。訪問不同包中的文件路徑

回答

1

您可以簡單地使用Properties類來獲取* .properties文件。例如,如果您直接從project name/src運行班級:

FileInputStream in = new FileInputStream("../properties/dev/propfile.properties"); // you can use absolute path here if you want 
Properties props = new Properties(); 
props.load(in); 
in.close(); 

FileOutputStream out = new FileOutputStream("../properties/dev/propfile.properties"); 
props.setProperty("Key", "Value"); 
props.store(out, "Comment"); // store changes 
out.close();