Java文件类boolean isHidden()方法(带示例)

文件类boolean isHidden() (File Class boolean isHidden())

  • This method is available in package java.io.File.isHidden().

    软件包java.io.File.isHidden()中提供了此方法。

  • This method is used to check whether the file is hidden or not.

    此方法用于检查文件是否隐藏。

  • The return type of this method is Boolean i.e. The value of this method is true or false if it returns true that means the file is hidden else return false so the file is not hidden.

    此方法的返回类型为布尔值,即,如果该方法的返回值为true,则该值为true或false,这意味着该文件已隐藏;否则返回false,因此该文件未被隐藏。

  • This method may raise an exception(i.e. Security Exception) if the write access is not given to the file.

    如果未授予文件写入权限,则此方法可能会引发异常(即Security Exception)。

Syntax:

句法:

    boolean isHidden(){
    }

Parameter(s):

参数:

We don't pass any object as a parameter in the method of the File.

我们不会在File方法中将任何对象作为参数传递。

Return value:

返回值:

The return type of this method is Boolean i.e. it returns true then in that case given file is hidden else returns false so the file is not hidden.

此方法的返回类型为布尔值,即返回true,则在这种情况下给定文件被隐藏,否则返回false,因此文件未被隐藏。

Java程序演示isHidden()方法的示例 (Java program to demonstrate example of isHidden() method)

// import the File class because we will use File class methods
import java.io.File;

// import the Exception class because it may raise an 
// exception when working with files
import java.lang.Exception;

public class ToCheckFileHidden {
    public static void main(String[] args) {
        try {
            // Specify the path of file and we use double slashes to 
            // escape '\' character sequence for windows otherwise 
            // it will be considerable as url.
            File file1 = new File("C:\\Users\\computer clinic\\OneDrive\\Articles\\myjava.txt");
            File file2 = new File("C:\\Users\\computer clinic\\OneDrive\\Articles\\myjava1.txt");

            // By using isHidden() is used to check whether the file 
            // is hidden or not . It returns true because given file is hidden.
            if (file1.isHidden())
                System.out.println("This file " + " " + file1.getName() + " " + "is hidden");
            else
                System.out.println("This file" + " " + file1.getName() + " " + "is not hidden");

            // By using isHidden() is used to check whether the 
            // file is hidden or not. It returns false because given file 
            // is not hidden.
            if (file2.isHidden())
                System.out.println("This file " + " " + file2.getName() + " " + "is hidden");
            else
                System.out.println("This file " + " " + file2.getName() + " " + "is not hidden");

        } catch (Exception e) {
            System.out.println("An error occurred.");
            e.printStackTrace();
        }
    }
}

Output

输出量

D:\Programs>javac ToCheckFileHidden.java

D:\Programs>java ToCheckFileHidden
This file  myjava.txt is hidden
This file  myjava1.txt is not hidden


翻译自: https://www.includehelp.com/java/file-class-boolean-ishidden-method-with-example.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值