/*
储存配置信息
*/
package iniDemo;
import java.util.*;
import java.io.*;
class IniDemo
{
public static void main(String[] args) throws IOException
{
//如果文件不存在,创建
File file=new File("count.ini");
if(!file.exists())
file.createNewFile();
//创建流,将数据导入到内存
FileInputStream fis=new FileInputStream(file);
Properties prop=new Properties();
prop.load(fis);
int count=0;
//获取键值
String value=prop.getProperty("time");
if(value!=null)
{
count=Integer.parseInt(value);
if(count>=5)
{
System.out.println("试用次数已到!");
return;
}
}
count++;
//设置键值
prop.setProperty("time",count+"");
//写入文件
FileOutputStream fos=new FileOutputStream(file);
prop.store(fos,"");
fis.close();
fos.close();
}
}
读写配置文件
最新推荐文章于 2022-11-12 00:13:24 发布