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.
如果未授予文件寫入權(quán)限,則此方法可能會(huì)引發(fā)異常(即Security Exception)。
Syntax:
句法:
boolean isHidden(){}Parameter(s):
參數(shù):
We don't pass any object as a parameter in the method of the File.
我們不會(huì)在File方法中將任何對(duì)象作為參數(shù)傳遞。
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");elseSystem.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");elseSystem.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.javaD:\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
總結(jié)
以上是生活随笔為你收集整理的Java文件类boolean isHidden()方法(带示例)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: rust拆掉墙_rust怎么拆自己的墙
- 下一篇: java美元兑换,(Java实现) 美元