javafileio

Filename in zip file is too long java


I have an application that take a zip file as input in Java. My application would decompress the zip file and inside the zip file there are some file contains filename exceeds 256 chars

Could I modify the filename of a file in zip without decompression

OS : linux/mac


Solution

  • It's more of a limitation of the file system used, than the OS itself.

    You can only change this by formatting the drives to a different file system that supports longer file names.

    Why you would need a file name that is couple of miles long is beyond me. But the only advice I can give is to try to shorten the file name.

    Edit

    Since you updated your question. Here's the correct answer. :)

    Typically, your approach is correct. Although if your zip contains longer filenames, you can truncate them. (Take the first, 250, ignore the rest. Now, you may have duplicate filenames. Add a number at the end because you got 5 chars left). Another option is to ask the user to enter a new file name.

    It is possible to edit the zip file itself, as long as you know how it is structured .etc.

    I'm not aware that Java built-in APIs allow editing zip files. Although a while back, I came across this library names DotNetZip for Microsoft.NET which allows all the typical functionality plus editing the entries inside a zip file, encryption, passwords .etc. (it is awesome btw)

    Look for a similar library for Java.