addressbook-level4 icon indicating copy to clipboard operation
addressbook-level4 copied to clipboard

FileUtil: isFileExists(File) may be unnecessary

Open PierceAndy opened this issue 7 years ago • 3 comments

The current method FileUtil#isFileExists(File) is basically a combination of two boolean method calls:

public static boolean isFileExists(File file) {
        return file.exists() && file.isFile();
}

However, as per the official docs for java.io.File#isFile(), this method returns "true if and only if the file denoted by this abstract pathname exists and is a normal file; false otherwise".

Since java.io.File#isFile() already checks for existence, FileUtil#isFileExists(File) appears unnecessary.

PierceAndy avatar Nov 05 '17 22:11 PierceAndy

This issue can be closed, as isFileExists is now edited to be:

    public static boolean isFileExists(Path file) {
        return Files.exists(file) && Files.isRegularFile(file);
    }

fzdy1914 avatar May 11 '19 12:05 fzdy1914

@fzdy1914

This issue can be closed, as isFileExists is now edited to be:

    public static boolean isFileExists(Path file) {
        return Files.exists(file) && Files.isRegularFile(file);
    }

Probably updated, but not closed though since conceptually the same issue exists, just with a different API. Files#isRegularFile(Path) already checks for file existence, so the call to Files.exists(file), and in fact even the whole isFileExists(Path) helper method, can be removed.

This comment will serve as the update.

pyokagan avatar May 12 '19 17:05 pyokagan

i would like to fix this!

delislej avatar Oct 22 '19 18:10 delislej