Java IO & NIO - Files.isDirectory() Examples

Code Snippets Java IO & NIO Java 


Class:

java.nio.file.Files

java.lang.Objectjava.lang.Objectjava.nio.file.Filesjava.nio.file.FilesLogicBig

Method:

public static boolean isDirectory(Path path,
                                  LinkOption... options)

Tests whether a file is a directory.

Parameters:
path - the path to the file to test
options - options indicating how symbolic links are handled
Returns:
true if the file is a directory; false if the file does not exist, is not a directory, or it cannot be determined if the file is a directory or not.


Examples


package com.logicbig.example.files;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class IsDirectoryExample {

public static void main(String... args) throws IOException {
Path dirPath = Files.createTempDirectory("test-dir");
System.out.println("path: " + dirPath);
boolean directory = Files.isDirectory(dirPath);
System.out.println("dir: " + directory);

Path filePath = Files.createTempFile("test-dir", ".txt");
System.out.println("path: " + filePath);
directory = Files.isDirectory(filePath);
System.out.println("dir: " + directory);
}
}

Output

path: C:\Users\Joe\AppData\Local\Temp\test-dir17730449894447819256
dir: true
path: C:\Users\Joe\AppData\Local\Temp\test-dir3419964740483799345.txt
dir: false




See Also