How to create an empty folder in a zip file.

Discussion in 'Spigot Plugin Development' started by fihgu, May 11, 2016.

  1. I'm currently using a method suggested by lots of people:
    Code (Text):
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(new File("./test.zip")));
            ZipEntry entry = new ZipEntry("test/");
            out.putNextEntry(entry);
            out.closeEntry();
            out.close();
    but instead of a folder, it creates a blank file, what am I doing wrong?
     
  2. MiniDigger

    Supporter

    mmmh, normal all file names suffixed with a / get threated as folders. thats strange. I know that \ creates a empty file. maybe you got something mixed but. you should try both slashes.
     
  3. ZipOutputStream does not support empty directories. If you don't put a file in there, the directory wont show up.
     
    • Like Like x 1
  4. I tried both.
    opened the result with winrar, both slash give me an empty file, but when extracted, they become a folder.
     
    #4 fihgu, May 11, 2016
    Last edited: May 11, 2016
  5. So problem solved?
     
  6. MiniDigger

    Supporter

    na, more like not solveable ^^