package yuwei.com;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class CountDemo {
public static void countRecord() throws IOException {
//创建对象
File file = new File("count.ini");
//创建文件
if(!file.exists()) {
file.createNewFile();
}
//创建集合
Properties prop = new Properties();
FileInputStream fis = new FileInputStream(file);
prop.load(fis);
int count = 0;
String values = prop.getProperty("time");
if(values!=null) {
count = Integer.parseInt(values);
if(count >= 5) {
System.out.println("fail");
}
}
count++;
prop.setProperty("time", count+"");
FileOutputStream fos = new FileOutputStream(file);
prop.store(fos, "");
fis.close();
fos.close();
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
countRecord();
}
}
限制运行次数
最新推荐文章于 2021-02-25 23:29:41 发布