请教一个properties中的问题
李慢慢i 2017-05-10 01:01:28 问题:出现了Exception in thread "main" java.lang.NumberFormatException,出现的行数是在第二个if语句的判断条件里,
at b.aproperties.test(aproperties.java:43),但是如果判断条件直接使用count就不会出错,想了好久没想出原因。
public class aproperties {
public static void main(String[] args) throws IOException {
test();
}
public static void test() throws IOException{
//找到目标文件
File file = new File("G:\\test.properties");
if(!file.exists()){
file.createNewFile();
}
//创建properties对象
Properties properties = new Properties();
//将配置文件的信息加载到properties中
properties.load(new FileInputStream(file));
int count = 0;
//获取第一次的value值
String value = properties.getProperty("count");
//保存使用的次数
if(null!=value){
count=Integer.valueOf(value);
}
if(Integer.valueOf(properties.getProperty("count"))>=3){
System.out.println("使用到达三次。");
}else{
count++;
}
properties.setProperty("count", Integer.toString(count));
properties.store(new FileOutputStream(file), "hh");
}
}