首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

求高手帮忙先上这段代码的3个有关问题

2013-01-28 
求高手帮忙先下这段代码的3个问题import java.util.*import java.io.*public class PropertiesDemo {pub

求高手帮忙先下这段代码的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口楼上正解!!

热点排行
Bad Request.