0

before this question gets closed for repetition - yes, I have read the other posts and their content was different, also the answers did not help in my case.

I have a zip file in my JEE-Project called Export.zip. It is located in the resources folder.

I am trying to unzip it and store it in a folder, which will be created by the Unzipper.

The Unzipper looks like this:

public String unzip(String zipFilePath, String destDirectory) throws IOException {
    String path = "";
    File destDir = new File(destDirectory);

    if (!destDir.exists()) {
        destDir.mkdirs();
    }

    ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
    ZipEntry entry = zipIn.getNextEntry();

    // iterates over entries in the zip file
    while (entry != null) {
        String filePath = destDirectory + File.separator + entry.getName();

        if (!entry.isDirectory()) {
            // if the entry is a file, extracts it
            extractFile(zipIn, filePath);

            path = filePath;

        } else {
            // if the entry is a directory, make the directory
            File dir = new File(filePath);
            dir.mkdir();
        }
        zipIn.closeEntry();
        entry = zipIn.getNextEntry();
    }
    zipIn.close();

    return path;
}

That is the method causing problems:

public String getPath() throws IOException {
     String destDirectory = "unzip/";
     String pathOuterZip =
     "../standalone/deployments/phonenumbersmanagement-0.0.1-SNAPSHOT.war/WEB-INF/classes/files/";
     this.logger.info("pathOuterZip: " + pathOuterZip);

     //THE LINE BELOW THROWS THE EXCEPTION!

     String filePathInnerZip = unzipper.unzip(pathOuterZip + "Export.zip",
     pathOuterZip + destDirectory);

     //THIS WONT BE EXECUTED CAUSE OF THE EXCEPTION
     this.logger.info("filePathInnerZip: " + filePathInnerZip);
     String pathExportAll = unzipper.unzip(filePathInnerZip, pathOuterZip
     + destDirectory);
     this.logger.info("pathExportAll: " + pathExportAll);

     return pathExportAll;
}

That is the error I am getting:

java.io.FileNotFoundException: ..\standalone\deployments\phonenumbersmanagement-0.0.1-SNAPSHOT.war\WEB-INF\classes\files\unzip\${_DUMMY_DIR}\${_NO_RESTORE}dummy.txt (Das System kann den angegebenen Pfad nicht finden/System cannot find Path) 

The problem is, I do not know why it points to the text file shown in the error.

To understand how the Export.zip looks like, this is the result when unzipping it:

${_DUMMY_DIR} (folder)
${exportWorkingDir} (folder)

The first folder contains the ${_NO_RESTORE}dummy.txt, which is mentioned in the stacktrace.

Can anybody help me to understand what is going on? Any help is appreciated. Thank you.

Bananaman
  • 5
  • 3
  • You appear to be counting on environment variables which are not resolved, and the file name cannot be found : ${_NO_RESTORE}dummy.txt is not a valid file name. – didiz Apr 22 '20 at 11:18
  • Can you elaborate on the environment variables? What do you mean here exactly? – Bananaman Apr 22 '20 at 11:20
  • 1
    You're writing to the deploy folder. This is wrong. – BalusC Apr 22 '20 at 21:26
  • @BalusC what would be the right thing to do then? – Bananaman Apr 23 '20 at 09:51
  • Click the abovementioned duplicate link for a question of someone else having exactly the same problem as you. Most probably you want the temp file approach. – BalusC Apr 23 '20 at 09:52
  • The post is pretty different. I am having problems with unzipping a zip-folder. – Bananaman Apr 23 '20 at 10:00
  • You're writing to the deploy folder. This is wrong. The abovelinked duplicate explains why this is wrong and shows several correct ways. – BalusC Apr 23 '20 at 10:37

0 Answers0