首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

关于Properties类的测试?该如何处理

2012-09-22 
关于Properties类的测试?[codeJava][/code]Properties settings new Properties()try{settings.load(n

关于Properties类的测试?
[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")));

热点排行