提问人:ZabbixJs 提问时间:11/7/2023 最后编辑:ZabbixJs 更新时间:11/7/2023 访问量:27
使用 JavaFX 的文件运行 jar 文件时出错
Error running jar file using file with JavaFX
问:
我需要根据我的项目创建一个 jar 文件,其中包含要读取的文件。但是当我通过双击运行这样的jar时,没有任何效果,但是如果我通过java -jar.jar格式的命令行运行它,则会出现以下错误:
java.nio.file.NoSuchFileException: HashSetFile.txt
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 myproject.JavaFXBuild.getListFile(JavaFXBuild.java:378)
at myproject.JavaFXController.initialize(JavaFXController.java:364)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2571)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2446)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2414)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:185)
at java.lang.Thread.run(Unknown Source)
下面是构建文件:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>
uip.gui.JavaFxRun
</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
这是抱怨的代码:
public static void getListFile(String fileName, Set<String> stringSet) {
try {
**InputStream inputStream = Files.newInputStream(Paths.get(fileName));**
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line = bufferedReader.readLine();
while (line != null) {
stringSet.add(line);
line = bufferedReader.readLine();
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, "ERROR ", e);
}
}
我需要逐行从文件中读取数据并将其放入 HashSet 中。但是当我尝试运行JAR文件时,发生以下错误。在这种情况下,应用程序会自行启动,但不会加载数据
答: 暂无答案
评论