I am trying to unzip files and it was recommended to me that I use codeJava.net's unzip utility however I cannot get it to work. The following is a snippet of my code that occurs when a button is pressed.
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();
}
}
It's meant to use the JavaFX file chooser to choose the file then turn the file path into strings before being used by the unzipper object. You can find the Unzip utility at http://www.codejava.net/java-se/file-io/programmatically-extract-a-zip-file-using-java. This is the error I get:
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)
Thanks for any help.
So basically the unzipUtility I was using had a fatal error... it couldn't unzip folders. So I did a quick google search and found: http://www.mkyong.com/java/how-to-decompress-files-from-a-zip-file/ Its not only works but its also easier to understand which is especially useful to a noob like me. Thx for all of you who commented, it really helped to steer me in the right direction :)