Properties的store方法与字符流必须挨在一起写吗?

rushing_coder 2019-06-03 10:21:07
目前编写了一个运行3次就会提示不能继续运行的程序

需要将配置文件加载进流中,但是当字符流提前定义后,计数器计到3次就会回跳到1


package OterDemo;

import java.io.*;
import java.util.Properties;

public class RunCountDemo {
public static void main(String[] args) throws IOException {
Properties prop = new Properties();
File file = new File("count.ini");
if(!file.exists())
file.createNewFile();
FileReader fr = new FileReader(file);
FileWriter fw = new FileWriter(file);
prop.load(fr);
String value = prop.getProperty("time");[code=java]

   int count=0;
if(value != null) {
count = Integer.parseInt(value);
if (count >= 3) {
System.out.println("u can not use it anymore");
return;
}
}
count++;
prop.setProperty("time", count + "");
prop.store(fw, "");
fw.close();
fr.close();

}
}
[/code]


但是将字符流位置换到setProperty()之后,程序就能正常运行

这个字符流位置会影响什么东西呢?为什么不能提前定义?
...全文
62 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
rushing_coder 2019-06-03
  • 打赏
  • 举报
回复
还有这个提问代码为什么不能写到一个块儿里,第一次发帖,格式不对大神们见谅啊

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧