日期:2014-05-20  浏览次数:20812 次

求高手帮忙先下这段代码的3个问题

import java.util.*;
import java.io.*;
public class PropertiesDemo {
public static void main(String[] args) throws IOException {
Properties prop=new Properties();
File files=new File("con.txt");
if(!files.exists()){
files.createNewFile();//为啥不能自动创建文件啊,报错如下
/*
Exception in thread "main" java.io.FileNotFoundException: con.txt (拒绝访问。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at PropertiesDemo.main(PropertiesDemo.java:12)
 
*/
}

FileInputStream frs=new FileInputStream(files);
prop.load(frs);

int count=0;
String s=prop.getProperty("time");
if(s!=null){
count=Integer.parseInt(s);//为啥不能用count=int()s;我记得以前貌似有这样的形式
if(count>=3){
System.out.println("你已超过使用次数");
return;
}
}
count++;
prop.setProperty("time", count+"");//这里count后为啥加上""

FileOutputStream fws=new FileOutputStream(files);
prop.store(fws, "");
frs.close();
fws.close();





}
public static void sop(Object obj){
System.out.println(obj);
}
}




------解决方案--------------------
2口楼上正解!!