Files is regular file java

Java Files isRegularFile(Path path, LinkOption. options)

Java Files isRegularFile(Path path, LinkOption. options) Tests whether a file is a regular file with opaque content.

Introduction

Tests whether a file is a regular file with opaque content.

The options array may be used to indicate how symbolic links are handled for the case that the file is a symbolic link.

By default, symbolic links are followed and the file attribute of the final target of the link is read.

If the option *LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS* is present then symbolic links are not followed.

Where it is required to distinguish an I/O exception from the case that the file is not a regular file then the file attributes can be read with the *#readAttributes(Path,Class,LinkOption[]) readAttributes* method and the file type tested with the BasicFileAttributes#isRegularFile method.

Syntax

The method isRegularFile() from Files is declared as:

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

The method isRegularFile() has the following parameter:

The method isRegularFile() returns true if the file is a regular file; false if the file does not exist, is not a regular file, or it cannot be determined if the file is a regular file or not.

The method isRegularFile() throws the following exceptions:

  • SecurityException — the case of the default provider, and a security manager is installed, its (SecurityManager#checkRead(String) checkRead) method denies read access to the file.

Example

The following code shows how to use Java Files isRegularFile(Path path, LinkOption. options)

import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; public class Main < public static void main(String[] args) throws Exception < Path path = FileSystems.getDefault().getPath("/home/docs/users.txt"); System.out.println(Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS)); > >
import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; public class Main < public static void main(String[] args) < Path path = FileSystems.getDefault().getPath("C:/tutorial/Java/JavaFX", "Demo.txt"); //method 1 boolean is_regular = Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS); > >
import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; public class Main < public static void main(String[] args) throws Exception < Path path = FileSystems.getDefault().getPath("/home/docs/users.txt"); displayFileAttributes(path);/* w w w . d e m o 2s . c o m */ > private static void displayFileAttributes(Path path) throws Exception < String format = "Exists: %s %n" + "notExists: %s %n" + "Directory: %s %n" + "Regular: %s %n" + "Executable: %s %n" + "Readable: %s %n" + "Writable: %s %n" + "Hidden: %s %n" + "Symbolic: %s %n" + "Last Modified Date: %s %n" + "Size: %s %n"; System.out.printf(format, Files.exists(path, LinkOption.NOFOLLOW_LINKS), Files.notExists(path, LinkOption.NOFOLLOW_LINKS), Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS), Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS), Files.isExecutable(path), Files.isReadable(path), Files.isWritable(path), Files.isHidden(path), Files.isSymbolicLink(path), Files.getLastModifiedTime(path, LinkOption.NOFOLLOW_LINKS), Files.size(path)); > >

  • Java Files getAttribute(Path path, String attribute, LinkOption. options)
  • Java Files isExecutable(Path path)
  • Java Files isReadable(Path path)
  • Java Files isRegularFile(Path path, LinkOption. options)
  • Java Files isSameFile(Path path, Path path2)
  • Java Files isWritable(Path path)
  • Java Files newBufferedReader(Path path, Charset cs)

demo2s.com | Email: | Demo Source and Support. All rights reserved.

Источник

Читайте также:  Opencart system library cache php
Оцените статью