[英]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中找到Unzip實用程序。 這是我得到的錯誤:
java.io.FileNotFoundException: F:\EbookReader\books\New folder\1.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
謝謝你的幫助。
所以基本上我正在使用的unzipUtility有一個致命錯誤……它無法解壓縮文件夾。 所以我做了一個快速的谷歌搜索,發現: http : //www.mkyong.com/java/how-to-decompress-files-from-a-zip-file/它不僅有效,而且更容易理解哪個是對像我這樣的菜鳥特別有用。 感謝所有對此發表評論的人,這確實有助於引導我朝正確的方向發展:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.