java代码运行不了

来源:百度知道 编辑:UC知道 时间:2024/07/04 15:13:01
import java.util.Properties;
import java.io.*;
class a {
public static void main(String[] args){
Properties obj = new Properties ();
try{
obj.load(new FileInputStream("count.txt"));
}
catch(Exception e)
{
obj.setProperty("count",String.valueOf(0));
}
int c = Integer.getInteger(obj.getProperty("count")) + 1;
System.out.println(c);
obj.setProperty("count", String.valueOf(c));
try{
obj.store(new FileOutputStream("count.txt"),"used times:");
}
catch(Exception e){
e.printStackTrace();
}
}
}
能编译,就是不能运行
int c = Integer.getInteger(obj.getProperty("count")) + 1;这行有异常,应该怎么改一下能正常运行
捕获这行异常之后能运行,但不能正确输出

这个程序是用来计数运行次数的

把int c = Integer.getInteger(obj.getProperty("count")) + 1
改成int c = Integer.parseInt(obj.getProperty("count")) + 1;

Integer java.lang.Integer.getInteger(String nm)

Determines the integer value of the system property with the specified name.

获取系统参数的整数值

你那个Properties obj 是系统参数么 - -!

好好看看API手册 看不懂e文的 官方有提供中文版的

int c = Integer.parseInt(obj.getProperty("count")) + 1;这样修改