我目前加載屬性文件是這樣的:如何從根目錄加載屬性文件?
private Properties loadProperties(String filename) throws IOException{
InputStream in = ClassLoader.getSystemResourceAsStream(filename);
if (in == null) {
throw new FileNotFoundException(filename + " file not found");
}
Properties props = new Properties();
props.load(in);
in.close();
return props;
}
然而,此刻我的文件規定在SCR \ user.properties路徑。
但是,當我想寫一個屬性文件:
properties.setProperty(username, decryptMD5(password));
try {
properties.store(new FileOutputStream("user.properties"), null);
System.out.println("Wrote to propteries file!" + username + " " + password);
這段代碼生成我在我的項目的根文件夾級別的新文件。
但我想有一個文件中寫入\讀取。
因此,如何做到這一點?
PS:當我想指定的路徑我得到「不允許修改文件...」
也許東西線嘗試更改權限? –