- import java.util.*;
- import java.io.*;
- class RunCount
- {
- public static void main(String[] args)
- {
- Properties prop = new Properties();
- File file = new File("count.ini");
- if(!file.exists())
- {
-
- try
- {
- file.createNewFile();
- System.out.println("haha");
- }
- catch (IOException e)
- {
- throw new RuntimeException(e.toString()+"yichang");
- }
-
- }
- FileInputStream fis = null;
- FileOutputStream fos = null;
- try
- {
- fis = new FileInputStream(file);
- fos = new FileOutputStream(file); //为什么我在这里new 一个FileOutput类. 就无法使文件持久化..
- // fos.write("temp=0".getBytes());
- //fos.newLine();
- // fos.flush();
- //System.out.println(fis.toString());
- System.out.println(file.length());
- prop.load(fis);
- int count = 0;
- System.out.println(prop);
- String value = prop.getProperty("temp");
- /*if(value == null)
- {
- System.out.println(value);
- fos.write("temp=0".getBytes());
- }
- else*/
- if(value != null)
- count = Integer.valueOf(value);
- count++;
- // System.out.println(prop);
- prop.setProperty("temp",count+"");
- // fos = new FileOutputStream(file); // 但我如果在这里new的话.文件能一直保持...
- prop.store(fos,"");
- prop.list(System.out);
- }
- catch (IOException e)
- {
- throw new RuntimeException(e.toString()+"文件不存在");
- }
- finally
- {
- if(fis != null)
- {
- try
- {
- fis.close();
- }
- catch (IOException e)
- {
- throw new RuntimeException(e.toString()+"haha");
- }
- }
- if(fos != null)
- {
- try
- {
- fos.close();
- }
- catch (IOException e)
- {
- throw new RuntimeException(e.toString()+"Hhasdas");
- }
- }
- }
-
- }
- }
复制代码 想问的问题是,这两个地方所new的FileOutputStream 对Properties有什么影响,?
文字表达不好..麻烦各位有时间看看.
|