我正在尝试为巡航控制系统开发一个 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());
}
}