Properties实例
来源:互联网 发布:网络线路自动切换 编辑:程序博客网 时间:2024/06/06 01:24
23 /********************设计一个程序,当运行一次程序,配置文件自增1*****************
***/
24 // 思路:因为程序要一一对应关系取值,所以用到Map集合,又因要从文件中读取,所以应用Properties集合
25 // 程序中要读写文件,所以要用到FileInputStream和FileWriter
26 public static void propertyAdd()throws IOException
27 {
28 Properties prop=new Properties();
29 File f=new File("info.ini");
30 if(!(f.exists()))
31 f.createNewFile();
32 FileInputStream fis=new FileInputStream(f);
33 prop.load(fis);
34 int count=0;
35 String value=prop.getProperty("name");
36 if(value!=null)
37 count=Integer.parseInt(value);
38 FileWriter fw=new FileWriter(f);
39 prop.setProperty("name",++count+""); //修改键值
40 //count++;
41 prop.store(fw,"");
42 if(count>=5)
43 {
44 System.out.println("运行次数太多了");
45 return;
46 }
47 }
48}
***/
24 // 思路:因为程序要一一对应关系取值,所以用到Map集合,又因要从文件中读取,所以应用Properties集合
25 // 程序中要读写文件,所以要用到FileInputStream和FileWriter
26 public static void propertyAdd()throws IOException
27 {
28 Properties prop=new Properties();
29 File f=new File("info.ini");
30 if(!(f.exists()))
31 f.createNewFile();
32 FileInputStream fis=new FileInputStream(f);
33 prop.load(fis);
34 int count=0;
35 String value=prop.getProperty("name");
36 if(value!=null)
37 count=Integer.parseInt(value);
38 FileWriter fw=new FileWriter(f);
39 prop.setProperty("name",++count+""); //修改键值
40 //count++;
41 prop.store(fw,"");
42 if(count>=5)
43 {
44 System.out.println("运行次数太多了");
45 return;
46 }
47 }
48}
0 0
- Properties实例
- log4j.properties常用实例
- properties配置文件操作实例
- Android Properties 使用实例
- IO properties 实例
- JAVA操作properties文件实例
- log4j.properties详解和实例
- 使用Properties文件配置实例的创建
- JAVA操作properties文件的代码实例
- log4j配置xml和properties实例
- 黑马程序员—SimpleDateFormat和 properties 实例
- Log4j.properties配置详解和实例
- Android 获取Properties文件内容实例
- java中properties的使用实例
- java.util.Properties.getProperty()方法实例
- log4j.properties配置详解与实例
- log4j.properties配置详解与实例
- log4j.properties配置详解与实例
- TCP
- JAVA学习之道
- Zepto Code Rush 2014-A. Feed with Candy(HACK)
- 一站式学习Wireshark(一):Wireshark基本用法
- VS2005 实现单文档中的窗口分割(SDI with split window)
- Properties实例
- svn备份还原(二)
- yuv422转420
- 支持泛型的C语言Swap函数
- 事务
- python:word
- 台湾大学林轩田机器学习笔记
- 【Unity新技术】Wayne Johnson(约翰逊●韦恩)讲解在Unity5的Audio技术(PPT译之上)
- 一站式学习Wireshark(二):应用Wireshark观察基本网络协议