当前位置: 代码迷 >> 综合 >> java properties 配置文件简单应用,使用配置文件限制用户使用次数。
  详细解决方案

java properties 配置文件简单应用,使用配置文件限制用户使用次数。

热度:31   发布时间:2024-02-06 18:49:32.0
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();}
}