【发布时间】:2014-10-04 22:35:17
【问题描述】:
我想在我用 unix 编写的 java 程序中添加更多命令,但在传递参数时遇到问题。我刚刚在 unix 中输入了之前使用文本文件作为程序参数的命令,它工作得很好,但想要求输入。试图自己修复它,但对 java 有点新
我有,
public static void main(String[] args)
{
String input = args[0];
///
String count = args[1];
File newF = new File(input); //
StartProcess start = new StartProcess(input, Integer.parseInt(count)); //begin
}
效果很好,然后尝试了这个,失败了
public static void main(String[] args)
{
//String inputFile = args[0]; //read the input file
Scanner scanner = new Scanner(new InputStreamReader(System.in));
System.out.println("Please enter file");
String input = scanner.nextLine();
System.out.println("Please enter number");
int count = scanner.nextInt();
//String interruptCounter = args[1]; //read the interrupt value
File newFile = new File(input); //create a new file with the input file
StartProcess being = new StartProcess(input, Integer.parseInt(count)); //begin
}
所以我得到了这些错误
CPU.java:24:错误:不兼容的类型 整数计数 = 扫描仪.nextLine(); ^ 必需:整数 找到:字符串 CPU.java:27:错误:找不到适合 parseInt(int) 的方法 StartProcess being = new StartProcess(input, Integer.parseInt(count)); //开始运行进程 ^ 方法 Integer.parseInt(String) 不适用 (实参int不能通过方法调用转换为String) 方法 Integer.parseInt(String,int) 不适用 (实际参数列表和形式参数列表的长度不同) 2 个错误
【问题讨论】:
-
编译错误似乎与您粘贴的代码无关。根据我的代码应该可以正常编译。