FileSystem类的isReadOnly()方法用于检查此文件系统是否仅允许对其文件存储区进行只读访问。如果文件系统仅允许对其文件存储进行读取访问,则此方法将返回true,否则返回false。
用法:
public abstract boolean isReadOnly()
参数:此方法不接受任何内容。
返回值:仅当此文件系统提供只读访问权限时,此方法才返回true。
以下示例程序旨在说明isReadOnly()方法:
示例1:
// Java program to demonstrate
// FileSystem.isReadOnly() method
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.Paths;
public class GFG {
public static void main(String[] args)
{
// create object of Path
Path path
= Paths.get(
"C:\\Movies\\document.txt");
// get FileSystem object
FileSystem fs = path.getFileSystem();
// apply isReadOnly() methods
boolean answer = fs.isReadOnly();
System.out.println("isReadOnly: "
+ answer);
}
}
输出:
示例2:
// Java program to demonstrate
// FileSystem.isReadOnly() method
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.Paths;
public class GFG {
public static void main(String[] args)
{
// create object of Path
Path path
= Paths.get(
"E:// Tutorials// file.txt");
// get FileSystem object
FileSystem fs = path.getFileSystem();
// apply isReadOnly() methods
boolean answer = fs.isReadOnly();
System.out.println(fs + "is ReadOnly = "
+ answer);
}
}
输出:
参考:https://docs.oracle.com/javase/10/docs/api/java/nio/file/FileSystem.html#isReadOnly()