package IO;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class 配置信息限制使用次数 {
public static void main(String[] args) throws IOException {
getProper();
}
private static void getProper() throws IOException {
File file = new File("F:\\text\\a.ini");
if(!file.exists()){
file.createNewFile();
}
FileInputStream fileInputStream = new FileInputStream(file);
Properties properties = new Properties();
properties.load(fileInputStream);
String value = properties.getProperty("time");
int count = 0;
if (value!=null){
count = Integer.parseInt(value);
if(count>=5) {
throw new RuntimeException("使用次数超过五次,请注册");
}
}
count++;
properties.setProperty("time",Integer.toString(count));
FileOutputStream fileOutputStream = new FileOutputStream(file);
properties.store(fileOutputStream,"");
fileInputStream.close();
fileOutputStream.close();
}
}