Search code examples
javaandroidfileunzip

mkdirs creates a file instead of creating a folder [JAVA]


I have a problem while unzipping a file, I get "open failed: ENOTDIR (Not a directory)" error.. After debugging I found out that the problem is in this function:
After I determine that the current ZipEntry is a Directory, I call this function with its path:

private void dirChecker(String dir) {
        File FiledirChecker = new File(PATH + dir); // PATH+dir = /mnt/sdcard/Pictures/Hafs

        if (!FiledirChecker.isDirectory())
            FiledirChecker.mkdirs();
    }

After this function is over, I browsed to Pictures directory, and Hafs isnt a Directory, instead its a 0 bytes file that is called "Hafs".

Why is this happening?

I should point out that for other directories (other than "Hafs"), mkdirs normally creates the folder! but only for this directory (Hafs) mkdirs doesnt make a directory but a file!


Solution

  • This is happening because elsewhere in the code, an empty file has already been created.

    Or the file is a leftover from your last run when your code couldn't create directories.