黑马程序员—IO流之Properties小练习

来源:互联网 发布:皮格马利翁效应 知乎 编辑:程序博客网 时间:2024/04/30 05:27

------- <a href="http://www.itheima.com" target="blank">android培训</a>、<a href="http://www.itheima.com" target="blank">java培训</a>、期待与您交流! ----------

package Twenty;
import java.io.*;
import java.util.*;
public class fourteen {
public static void main(String[] args)throws IOException {
Properties pop =new Properties();
File file=new File("count.ini");//对文件进行封装可以判断数据,而流不行。
if(!file.exists())
file.createNewFile();
FileInputStream fis=new FileInputStream(file);
pop.load(fis);
int count=0;
String value=pop.getProperty("time");
if(value!=null)
count=Integer.parseInt(value);
if(count>=5)
{
System.out.println("试用期结束,请缴费");
return;
}
count++;
pop.setProperty("time",+ count+"");
FileOutputStream fos=new FileOutputStream(file);
pop.store(fos, "");
fos.close();
fis.close();
}


}

------- <a href="http://www.itheima.com" target="blank">android培训</a>、<a href="http://www.itheima.com" target="blank">java培训</a>、期待与您交流! ----------



0 0
原创粉丝点击