property 的setProperty怎么没改变文件中的值,只是改变了内存中的值
public static void main(String[] args) {String fileName = "start.txt";//
File file = null;
InputStream in;
OutputStream ops ;
String start;
try {
file = new File(test.class.getResource(fileName).toURI());
System.out.println(test.class.getResource(fileName).toURI());
in = new FileInputStream(file);
Properties p = new Properties();
p.load(in);
in.close();
start = p.getProperty("start");
System.out.println(start);
ops = new FileOutputStream(file);
p.setProperty("start", "10001");
// p.store(ops, "update start ");
p.store(ops, "Update start 10001");
ops.flush();
ops.close();// 关闭流
// start = p.getProperty("start");
// System.out.println(start);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
start.txt与test.java 同一个文件夹目录下,里面的内容是start=0,我想通过运行这个程序修改start的值,但是我这个程序只修改了内存中的值,并没修改文件中的值,在线求解 propertysetProperty property setProperty 流 --------------------编程问答-------------------- 看看是不是因为不是Properties文件造成的。不要用txt --------------------编程问答--------------------
不是,改成properties文件也没用 --------------------编程问答-------------------- 你到你项目下的bin/start.txt下看看,是你路径搞错了,好好理解test.class.getResource(fileName)这代码的意思
补充:Java , Java SE