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();
  }
问:帮我看看哪里有错,我找不到,谢谢咯。

解决方案 »

  1.   

    报异常了吗?没有出现异常信息的话,那就是路径的问题:
    settings.load(new FileInputStream("count.txt")); //加载文件.
    修改如下:
    settings.load(new FileInputStream(new File("d:"+File.separator+"count.txt")));
      

  2.   

    是这样的:
    The method getProperty(String) is undefined for the type Properties
    The method setProperty(String, String) is undefined for the type Properties
    The method store(FileOutputStream, String) is undefined for the type Properties at com.propertiesfile.Properties.main(Properties.java:13)(也就是大哥你说的这行)
    我已经引入util包和io包了,好像没有找到count.txt,真找不到是什么问题,按 你这样子改也不行。