[英]working with a command prompt to execute a java program
我有一个从文件读取的程序,并将内容存储在链接列表中,然后将链接列表的内容写入另一个文件,
我有三类:1-代理(主类)2-状态3- LinkedList
calss Agent的内容是:
public class Agent{
public static void main(String[] args) {
int n_args = args.length;
if (n_args!=4) {
System.out.println("ERROR: ILLEGAL NUMBER OF ARGUMENTS.");
System.out.println("Number of arguments must be 4");
return;
}
String mapFile = args[0];
String commandsFile = args[1];
String finalMapFile = args[2];
String logFile = args[3];
State s = new State();
s.read(args[0]);
s.read2(args[1]);
s.Action();
s.writemap(args[2]);
s.write(args[3]);
}
}
我需要它们的所有方法都在State类中,因此我创建了State对象,然后我完成了所有工作,但问题是当我在编写此命令时从命令提示符执行它时:
C:\\ Users \\ prof \\ Desktop \\ Compilation> javac Agent.java
我收到此消息:
Agent.java:27:错误:未报告的异常IOException; 必须被抓住或宣布被抛出
s.read(args[0]);
^
Agent.java:28: error: unreported exception IOException; must be caught or declared to be thrown
s.read2(args[1]);
^
Agent.java:30: error: unreported exception UnsupportedEncodingException; must be caught or declared to be thrown
s.writemap(args[2]);
^
Agent.java:31: error: unreported exception UnsupportedEncodingException; must be caught or declared to be thrown
s.write(args[3]);
^
4 errors
我希望我的程序按以下方式工作:
java Agent mapFile.txt commandsLine.txt finalMap.txt logFile.txt
有什么帮助吗?
这与命令行无关,也与您尝试执行的操作无关。 您的代码中有一个错误:您没有捕获异常。
至少,您应该将main()
内容包装在try-catch
块中。 https://docs.oracle.com/javase/tutorial/essential/exceptions/try.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.