使用 javaFX 解压缩文件时出错
Error unzipping a file with javaFX
我正在尝试解压缩文件,有人建议我使用 codeJava.net 的解压缩实用程序,但我无法使用它。以下是按下按钮时出现的我的代码片段。
public void fileSelector(Stage primaryStage) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Resource File");
fileChooser.getExtensionFilters().addAll(new ExtensionFilter("ZIP FILES ONLY", "*.zip"));
File selectedFile = fileChooser.showOpenDialog(primaryStage);
if (selectedFile != null) {
System.out.println(selectedFile);
UnzipUtility unzipper = new UnzipUtility();
String destination = System.getProperty("user.dir");
String finalDestination = destination + "\books";
System.out.println(finalDestination);
String initialDestination = selectedFile.getPath();
System.out.println(initialDestination);
try {
System.out.println("unzipping ... beep boop beep");
unzipper.unzip(initialDestination, destination);
}
catch (Exception e) {
e.printStackTrace();
}
}
它的意思是使用JavaFX文件选择器选择文件,然后将文件路径转换为字符串,然后再被解压缩对象使用。您可以在 http://www.codejava.net/java-se/file-io/programmatically-extract-a-zip-file-using-java 找到解压缩实用程序。
这是我得到的错误:
java.io.FileNotFoundException: F:\EbookReader\books\New folder.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
感谢您的帮助。
所以基本上我使用的 unzipUtility 有一个致命错误...它无法解压缩文件夹。所以我快速 google 搜索并发现:http://www.mkyong.com/java/how-to-decompress-files-from-a-zip-file/
它不仅有效,而且更容易理解,这对像我这样的菜鸟特别有用。感谢所有发表评论的人,这真的有助于引导我朝着正确的方向前进:)
我正在尝试解压缩文件,有人建议我使用 codeJava.net 的解压缩实用程序,但我无法使用它。以下是按下按钮时出现的我的代码片段。
public void fileSelector(Stage primaryStage) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Resource File");
fileChooser.getExtensionFilters().addAll(new ExtensionFilter("ZIP FILES ONLY", "*.zip"));
File selectedFile = fileChooser.showOpenDialog(primaryStage);
if (selectedFile != null) {
System.out.println(selectedFile);
UnzipUtility unzipper = new UnzipUtility();
String destination = System.getProperty("user.dir");
String finalDestination = destination + "\books";
System.out.println(finalDestination);
String initialDestination = selectedFile.getPath();
System.out.println(initialDestination);
try {
System.out.println("unzipping ... beep boop beep");
unzipper.unzip(initialDestination, destination);
}
catch (Exception e) {
e.printStackTrace();
}
}
它的意思是使用JavaFX文件选择器选择文件,然后将文件路径转换为字符串,然后再被解压缩对象使用。您可以在 http://www.codejava.net/java-se/file-io/programmatically-extract-a-zip-file-using-java 找到解压缩实用程序。 这是我得到的错误:
java.io.FileNotFoundException: F:\EbookReader\books\New folder.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
感谢您的帮助。
所以基本上我使用的 unzipUtility 有一个致命错误...它无法解压缩文件夹。所以我快速 google 搜索并发现:http://www.mkyong.com/java/how-to-decompress-files-from-a-zip-file/ 它不仅有效,而且更容易理解,这对像我这样的菜鸟特别有用。感谢所有发表评论的人,这真的有助于引导我朝着正确的方向前进:)