java filesystem_Java FileSystem isReadOnly()用法及代码示例

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();

// print

System.out.println("isReadOnly: "

+ answer);

}

}

输出:

072be6d91888fc94e33286d41f59e845.png

示例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();

// print

System.out.println(fs + "is ReadOnly = "

+ answer);

}

}

输出:

6cdad246056b1f618e5a4c12cb261e28.png

参考:https://docs.oracle.com/javase/10/docs/api/java/nio/file/FileSystem.html#isReadOnly()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值