Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

FileUtil: isFileExists(File) may be unnecessary #728

Open
PierceAndy opened this issue Nov 5, 2017 · 3 comments
Open

FileUtil: isFileExists(File) may be unnecessary #728

PierceAndy opened this issue Nov 5, 2017 · 3 comments

Comments

@PierceAndy
Copy link
Contributor

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.

@fzdy1914
Copy link
Contributor

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);
    }

@pyokagan
Copy link
Contributor

@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.

@delislej
Copy link

i would like to fix this!

delislej added a commit to delislej/addressbook-level4 that referenced this issue Oct 22, 2019
fix issue se-edu#728

hopefully this is what you wanted!
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants