Java读写配置文件prop.properties

Java读写配置文件prop.properties 

@Test
public void fun() throws IOException{
Properties prop=new Properties();
String path2=this.getClass().getResource("/test/conf/file.properties").getPath();
System.out.println(path2);
InputStream in=new BufferedInputStream(new FileInputStream(path2));
prop.load(in);
Integer count=Integer.parseInt(prop.getProperty("count"));
System.out.println(count);
in.close();

FileOutputStream oFile = new FileOutputStream(path2, false);
count++;
prop.setProperty("count", count.toString());
prop.store(oFile,"count" );
oFile.close();
//6位数,不足补零
String string=String.format("%6d", count).replace(" ", "0");
System.out.println(string);
}

猜你喜欢

转载自www.cnblogs.com/mryangbo/p/9267380.html