0

Im trying to zip my created folder. Right now im testing localy and it create folder but after that i want to zip it.

This is my code for zip:

public static void pack(final String sourceDirPath, final String zipFilePath) throws IOException {
    Path p = Files.createFile(Paths.get(zipFilePath));
    try (ZipOutputStream zs = new ZipOutputStream(Files.newOutputStream(p))) {
        Path pp = Paths.get(sourceDirPath);
        Files.walk(pp).filter(path -> !Files.isDirectory(path)).forEach(path -> {
            ZipEntry zipEntry = new ZipEntry(pp.relativize(path).toString());
            try {
                zs.putNextEntry(zipEntry);
                Files.copy(path, zs);
                zs.closeEntry();
            } catch (IOException e) {
                System.err.println(e);
            }
        });
    } }

But im getting an error AccessDeniedException. Is there any option to zip created folder, i dont want to zip file because in that folder i will have subfolders, so i want to zip main folder. Any suggestion how can i achive that?

1
  • What is zipFilePath? and does it name a directory or a file? Commented Jul 21, 2022 at 10:15

1 Answer 1

1

According to: Getting "java.nio.file.AccessDeniedException" when trying to write to a folder

I think you should add the filename and the extension to your 'zipFilePath', for example: "C:\Users\XXXXX\Desktop\zippedFile.zip"

Sign up to request clarification or add additional context in comments.

1 Comment

thats it tnx :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.