写入配置文件并读取值demo
2018-03-20 14:06
225 查看
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(); } }
相关文章推荐
- Properties配置文件读取/写入例子
- PropertiesHelper——配置文件读取和写入工具类
- python读取/写入配置文件ini方法
- Java读取/写入Yaml配置文件
- 写入配置的函数WritePrivateProfileString和读取配置文件的函数GetPrivateProfileInt和GetPrivateProfileString
- python 学习记录(11)-文件处理/读取文件/文件写入内容/文件删除/文件复制/文件重命名/后缀名/内容查找与替换/文件比较/ 配置文件访问/目录创建与删除/遍历目录/定向输出
- Properties配置文件读取Demo
- java IO 使用Properties设置键值对配置信息 写入文件和从文件中读取
- 向INI配置文件写入\读取数据
- Python 读取写入配置文件 —— ConfigParser
- Java配置文件Properties的读取、写入与更新操作
- C++读取、写入配置文件
- Python 读取写入配置文件 —— ConfigParser
- properties 读取和写入配置文件
- Java配置文件Properties的读取、写入与更新操作
- java中经常用到的读写配置文件的信息properties属性的写入,读取例子
- java Properties配置文件写入与读取
- Python Configparser模块读取、写入配置文件
- Java配置文件Properties的读取、写入与更新操作
- c# 使用WINAPI 进行读取写入配置文件