java store()_Java FileStore isReadOnly()用法及代码示例

如果此文件存储区是只读的,则FileStore类的isReadOnly()方法用于返回true。如果文件存储不支持文件的写操作或其他更改,则称为只读。如果尝试创建文件,打开现有文件进行写入等,则将引发IOException。

用法:

public abstract String isReadOnly()

参数:此方法不接受任何内容。

返回值:仅当此文件存储为只读时,此方法返回true。

以下示例程序旨在说明isReadOnly()方法:

示例1:

// Java program to demonstrate

// FileStore.isReadOnly() method

import java.io.IOException;

import java.nio.file.FileStore;

import java.nio.file.Files;

import java.nio.file.Path;

import java.nio.file.Paths;

public class GFG {

public static void main(String[] args)

throws IOException

{

// create object of Path

Path path

= Paths.get(

"E:\\Tutorials\\file.txt");

// get FileStore object

FileStore fs

= Files.getFileStore(path);

// print FileStore name

System.out.println("FileStore Name: "

+ fs.name());

// is file is readable

boolean isReadOnly = fs.isReadOnly();

System.out.println("FileStore isReadOnly:"

+ isReadOnly);

}

}

输出:

97c9549af99893c19866a16513150902.png

示例2:

// Java program to demonstrate

// FileStore.isReadOnly() method

import java.io.IOException;

import java.nio.file.FileStore;

import java.nio.file.Files;

import java.nio.file.Path;

import java.nio.file.Paths;

public class GFG {

public static void main(String[] args)

throws IOException

{

// create object of Path

Path path

= Paths.get(

"C:\\Movies\\001.txt");

// get FileStore object

FileStore fs

= Files.getFileStore(path);

// print FileStore name

System.out.println("FileStore Name: "

+ fs.name());

// is file is readable

boolean isReadOnly = fs.isReadOnly();

System.out.println("FileStore isReadOnly:"

+ isReadOnly);

}

}

输出:

bf0b23fbdd25bc131945a14de86073b1.png

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值