Victor Laerte Oliveira Victor Laerte Oliveira - 6 months ago 60
Java Question

Invalid character in zipfile path (Windows)

I have to unzip one file that contains a invalid path for Windows OS:


data:image, in windows it's not permited to be directory with : in path
then my code to unzip got this exception The filename, directory name, or volume label syntax is incorrect

How can I fix it, changing : for another character (underline for example) or just skip this directory.

I've tried this code below, but it doesn't work:

while (ze != null) {
String fileName = ze.getName();
File newFile = new File(outputFolder + File.separator + fileName);

String nameFile = newFile.getAbsolutePath();
if (nameFile.contains(":")){
nameFile.replaceAll(":", "_");
newFile = new File(nameFile);

actually my path needs to contain : because the complete path needs to begin with C:\, please give me one solution (Detail: it works fine in Mac)

 while (ze != null) {
                String fileName = ze.getName();

                if (fileName.contains(":")){
                    fileName = fileName.replaceAll(":", "_");