Looking in the source code for differences, they both do the same with 1 big difference. The notExist(...) method has an additional exception that can be caught.
Exist:
public static boolean exists(Path path, LinkOption... options) { try { if (followLinks(options)) { provider(path).checkAccess(path); } else { // attempt to read attributes without following links readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); } // file exists return true; } catch (IOException x) { // does not exist or unable to determine if file exists return false; } }
Does not exist:
public static boolean notExists(Path path, LinkOption... options) { try { if (followLinks(options)) { provider(path).checkAccess(path); } else { // attempt to read attributes without following links readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); } // file exists return false; } catch (NoSuchFileException x) { // file confirmed not to exist return true; } catch (IOException x) { return false; } }
As a result, the differences are as follows:
!exists(...) returns the file as non-existent if an IOException is IOException when trying to retrieve the file.
notExists(...) returns the file as non-existent, making sure that a specific IOException subexception NoSuchFileFound and that it is not another sub-element of the IOException , raising an NoSuchFileFound result
Skepi source share