Java - Checking a File or Directory

Java - Checking a File or Directory

You have a Path that representing a file or directory, but does that file exist on the file system? Is it readable? Writable? Executable?

Verifying the Existence of a File or Directory


Files.exists(path)
Verify whether a particular Path exists, or does not exist.

Checking File Accessibility

To verify that the program can access a file as needed:
isReadable(Path)
isWritable(Path)
isExecutable(Path)

The following code snippet verifies that a particular file exists and that the program has the ability to execute the file.

Path file = ...;
boolean isRegularExecutableFile = Files.isRegularFile(file) &
         Files.isReadable(file) & Files.isExecutable(file);


Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)