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 propertysetProperty流
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 propertysetProperty流
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货