package ZHANG.API; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; public class PropertiesFile { /** * @param args * @throws IOException * @throws FileNotFoundException */ public static void main(String[] args) { Properties settings = new Properties(); try { settings.load(new FileInputStream("count.txt")); } catch (FileNotFoundException e) { settings.setProperty("count", String.valueOf(0)); e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //settings.get("count"); int i = Integer.parseInt(settings.getProperty("count"))+1; System.out.println("这是第"+i+"次运行.."); //settings.put("count",new Integer(i).toString()); settings.setProperty("count", new Integer(i).toString()); try { settings.store(new FileOutputStream("count.txt"), "program is use:"); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }