Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

java.nio.file.AccessDeniedException error?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading