A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© 奋发吧小白 高级黑马   /  2014-9-17 21:51  /  1558 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 奋发吧小白 于 2014-9-17 21:54 编辑

package copydirectory;
import java.util.*;
import java.io.*;
public class RunTime {

        public static void main(String[] args) throws Exception{
                // TODO Auto-generated method stub
                Properties porp = new Properties();
                File file = new File("D:\\info.txt");
                if(!file.exists())
                {
                        file.createNewFile();
                }
                FileInputStream fis = new FileInputStream(file);
                porp.load(fis);
                int count = 0;
                String value = porp.getProperty("time");
                if(value!=null)
                {
                        count = Integer.parseInt(value);
                        if(count>6)
                        {
                                System.out.println("您使用次数已到,请激活");
                                return;
                        }
                }
                count++;
                porp.setProperty("time", count+"");//setProperty() 方法两个参数 都是 String 类型,count+""和“count”这两种写法 不都是String类型吗?                                                                         //为什么“count”这样写 程序就不能正常运行?
                FileOutputStream fos = new FileOutputStream(file);
                porp.store(fos, "");
                fis.close();
                fos.close();
        }

}



4 个回复

倒序浏览
定义的count是个整型的变量,如果是“count”那就是字符串count了,跟count变量的值没有任何关系了,count+“”:是把count变量的值变成字符串的。
回复 使用道具 举报
苏乞儿 发表于 2014-9-17 22:02
定义的count是个整型的变量,如果是“count”那就是字符串count了,跟count变量的值没有任何关系了,count+ ...

谢谢 受教了!
回复 使用道具 举报
同样受教了,thanks
回复 使用道具 举报
MeryStyle 来自手机 中级黑马 2014-9-18 08:51:33
报纸
一楼正解!!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马