import java.util.*;
import java.io.*;
public class RunCount2{
public static void main(String[] args)throws IOException{
Properties pro=new Properties();
File f2=new File("delete.ini");
if(!f2.exists())
{
f2.createNewFile();
}
FileInputStream in=new FileInputStream(f2);

pro.load(in);

int count=0;
String value=pro.getProperty("times");
if(value!=null)
count=Integer.parseInt(value);
count++;
pro.setProperty("times",count+"");
FileOutputStream out=new FileOutputStream(f2);//字节输出流所在的位置
pro.store(out,"times of removement");
in.close();
out.close();
}
}
上面代码可以更改delete.ini文件中的times所对应的值
下面的代码却不可以import java.util.*;
import java.io.*;
public class RunCount2{
public static void main(String[] args)throws IOException{
Properties pro=new Properties();
File f2=new File("delete.ini");
if(!f2.exists())
{
f2.createNewFile();
}
FileInputStream in=new FileInputStream(f2);
FileOutputStream out=new FileOutputStream(f2);//字节输出流所在的位置
pro.load(in);

int count=0;
String value=pro.getProperty("times");
if(value!=null)
count=Integer.parseInt(value);
count++;
pro.setProperty("times",count+"");

pro.store(out,"times of removement");
in.close();
out.close();
}
}
两串代码唯一的区别在于字节输出流初始化创建的位置不同
求大神解释为何字节输出流的位置不同能够导致输出结果不一样?