本帖最后由 黑马张伟 于 2011-12-24 09:23 编辑
package file;
import java.io.*;
import java.util.*;
public class Property {
public static void main(String[] args) throws IOException {
Properties prop = new Properties();
File file= new File("count.init");
if(!file.exists())
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("您好使用次数已到,拿钱!");
}
}
count++;
prop.setProperty("time", count+"");
FileOutputStream fos = new FileOutputStream(file);
prop.store(fos, "");
fos.close();
fis.close();
}
}
错误提示:
Exception in thread "main" java.io.FileNotFoundException: file (系统找不到指定的文件。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at file.Property.main(Property.java:37)
|