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

代码如下,其中有一句是prop.setProperty("times",count+"");,properties里面存储的都是String型的,但int型的count+“”可以将int型的count转换为String嘛?具体原理是什么?

import java.io.*;
import java.util.*;
class  runCount
{
        public static void main(String[] args) throws Exception
        {
                File file=new File("info.ini");
                if(!file.exists())
                        file.createNewFile();
                Properties prop=new Properties();
                FileInputStream fis=new FileInputStream(file);
                prop.load(fis);
                int count=0;
                String value=prop.getProperty("times");
                if(value!=null)
                {count=Integer.parseInt(value);
                        if(count>=5)
                                {
                                        System.out.println("您好,次数已够");
                                        return;
                                       
                                }
                }
                count++;
                prop.setProperty("times",count+"");
                FileOutputStream fos=new FileOutputStream(file);
                prop.store(fos,"");

        }
}

4 个回复

正序浏览
你们都对。。。我看错了哈哈
回复 使用道具 举报
...properties是hashtable的子类 跟hashmap都是Map体系里的 存的是键值对 键是string  值是Integer啊
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马