[code=Java][/code]
Properties settings = new Properties();
try{
settings.load(new FileInputStream("count.txt")); //加载文件.
}catch(IOException e){
settings.setProperty("count", String.valueOf(0));
}
int c = Integer.parseInt(settings.getProperty("count"))+1;
System.out.println("运行了第"+c+"次!"); //打印
settings.setProperty("count", new Integer(c).toString()); //保存count属性
try{
settings.store(new FileOutputStream("count"), "used for count"); //保存到文件
}catch(IOException e){
e.printStackTrace();
}
问:帮我看看哪里有错,我找不到,谢谢咯。
------解决方案--------------------------------------------------------
报异常了吗?
没有出现异常信息的话,那就是路径的问题:
settings.load(new FileInputStream("count.txt")); //加载文件.
修改如下:
settings.load(new FileInputStream(new File("d:"+File.separator+"count.txt")));