我正在尝试开发一个用于巡航控制系统的java应用程序。但我在没有这样的文件异常中遇到了问题。因为我在java编码方面有点新手。我不确定为什么会出现这个问题。我的代码是-
public static void main(String[] commandLineArgs) throws IOException {
Path input_path = Paths.get(commandLineArgs[0]);
List<InputState> input_states = StateInput.input_states_from_file(input_path);
Timer timer = new Timer(new CruiseControlSystem());
List<OutputState> output_states = timer.pulse_from_input(input_states);
for (OutputState s : output_states){
System.out.println(s.format());
}
}我发现的错误是-
Exception in thread "main" java.nio.file.NoSuchFileException: commandLineArgs[0]
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(Unknown Source)
at java.nio.file.Files.newByteChannel(Unknown Source)
at java.nio.file.Files.newByteChannel(Unknown Source)
at java.nio.file.spi.FileSystemProvider.newInputStream(Unknown Source)
at java.nio.file.Files.newInputStream(Unknown Source)
at java.nio.file.Files.newBufferedReader(Unknown Source)
at java.nio.file.Files.readAllLines(Unknown Source)
at StateInput.input_states_from_file(StateInput.java:31)
at CommandLine.main(CommandLine.java:23)我的主要方法是-
public static void main(String[] commandLineArgs) throws IOException {
Path input_path = Paths.get(commandLineArgs[0]);
List<InputState> input_states = StateInput.input_states_from_file(input_path);
Timer timer = new Timer(new CruiseControlSystem());
List<OutputState> output_states = timer.pulse_from_input(input_states);
for (OutputState s : output_states){
System.out.println(s.format());
}
}

发布于 2016-10-15 07:25:47
在程序参数文本框中,当前有"commandLineArgs".您需要将"commandLineArgs“更改为包含输入状态的文件的路径。像"/data/input-states".这样的东西

发布于 2016-10-15 08:31:50
我的主要方法是:
Path input_path = Paths.get(commandLineArgs[0]);不,它不是。你传递的是"commandLineArgs[0]"作为参数。你的意思是commandLineArgs[0],没有引号。
发布于 2016-10-15 06:16:41
在运行程序时,您没有向main方法传递任何参数。
你还可以添加你是如何运行这个的吗?
https://stackoverflow.com/questions/40052723
复制相似问题