java.io.FileNotFoundException: file:/home/oracle/yqpt/client/golaxy.jar!/myconfig.properties (No such file or directory)
windows下可以通过如下方式来读写properties文件:
************************************
读取属性值:
ResourceBundle rb = ResourceBundle.getBundle("myconfig");
String value = rb.getString(key);
修改属性值:
Properties prop = new Properties();
ResourceBundle rb = ResourceBundle.getBundle("myconfig");
String a = rb.getString("startTime");
in = ClassLoader.getSystemResourceAsStream("myconfig.properties");
URL url = ClassLoader.getSystemResource("myconfig.properties");
prop.load(in);
in.close();
prop.setProperty(key, value);
out = new FileOutputStream(url.getPath());
prop.store(out, "change");
out.close();
*************************************
同样的程序(把java工程打成jar包)放到Linux下就报如下的异常:
java.io.FileNotFoundException: file:/home/oracle/yqpt/client/golaxy.jar!/myconfig.properties (No such file or directory)
读没有问题,就是写的时候找不到文件。
url.getPath()得到的是properties文件的绝对路径,