package IO;
import java.io.*;
import java.util.Properties;
import javax.management.RuntimeErrorException;
public class PropertiesTest {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
getAppCount();
}
public static void getAppCount() throws IOException {
File config = new File("count.Properties");
if (!config.exists()) {
config.createNewFile();
}
FileInputStream fis = new FileInputStream(config);
Properties prop = new Properties();
prop.load(fis);
String value = prop.getProperty("time");
int count=0;
if (value!=null) {
count = Integer.parseInt(value);
if (count>=10) {
throw new RuntimeException("请注册!!!");
}
}
count++;
int use=10-count;
System.out.println("还有"+use+"次使用机会!!");
prop.setProperty("time", count+"");
FileOutputStream fos = new FileOutputStream(config);
prop.store(fos, "");
fos.close();
fis.close();
}
}
写入配置文件并读取值demo
猜你喜欢
转载自blog.csdn.net/zuozewei/article/details/79624851
今日推荐
周排行