0
大家好我想創建一個屬性在我的代碼中動態文件作爲在動態web項目中創建屬性文件?
package abc.in;
import java.io.*;
import java.util.Properties;
public class DBConnection {
OutputStream out = null;
public void SetAllProps() {
try {
Properties props = new Properties();
File f = new File("myApp.properties");
if (f.exists()) {
props.load(new FileReader(f));
// Change your values here
props.setProperty("ServerAddress", "ThatNewCoolValue");
} else {
// Set default values?
props.setProperty("ServerAddress", "DullDefault");
props.setProperty("ServerPort", "8080");
props.setProperty("ThreadCount", "456");
f.createNewFile();
}
out = new FileOutputStream(f);
props.store(out, "This is an optional header comment string");
System.out.println(props.get("ServerPort"));
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException ex) {
System.out
.println("IOException: Could not close myApp.properties output stream; "
+ ex.getMessage());
ex.printStackTrace();
}
}
}
}
}
我網絡的Java項目這樣做,那麼它會創建上述名爲「myApp.properties」但是當我執行屬性文件動態web項目中的代碼相同,它不會創建任何屬性文件。我究竟做錯了什麼。期待你的回答。在此先感謝