I am playing a bit with the new Java 7 IO features, actually I trying to receive all the xml files of a folder. But this throws an exception when the folder does not exist,
From SonarLint, if you already have the path, use path.toFile().exists() instead of Files.exists for better performance.
The
Files.existsmethod has noticeably poor performance in JDK 8, and can slow an application significantly when used to check files that don't actually exist.
The same goes forFiles.notExists,Files.isDirectoryandFiles.isRegularFile.
Noncompliant Code Example:
Path myPath;
if(java.nio.Files.exists(myPath)) { // Noncompliant
// do something
}
Compliant Solution:
Path myPath;
if(myPath.toFile().exists())) {
// do something
}