因为没有这个路径,我的这里找不到路径,我在判断文件存在时添加了创建文件路径的语句:
- import java.io.*;
- import java.util.*;
- public class RunCount
- {
- public static void main(String[] args) throws IOException
- {
- Properties prop = new Properties();
- String str = "d://system//day18//count.ini";
- File file = new File(str);
- if(!file.exists())
- new File(str.substring(0, str.lastIndexOf("//"))).mkdirs();
- file.createNewFile();
- FileInputStream fis = new FileInputStream(file);
- 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,"");
- fos.close();
- fis.close();
- }
- }
复制代码
也可以运行 |