日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

Java File类boolean isFile()方法(带示例)

發(fā)布時間:2025/3/11 java 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java File类boolean isFile()方法(带示例) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

File類boolean isFile() (File Class boolean isFile())

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

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

  • This method is used to check whether the file is specified by filepath is a file or not.

    此方法用于檢查filepath指定的文件是否為文件。

  • 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 represented by filepath is a file else return false so it is not a file.

    此方法的返回類型為布爾值,即,如果該方法返回true,則該值為true或false,這意味著該文件由filepath表示是文件,否則返回false,因此它不是文件。

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

    如果未授予文件寫入權(quán)限,則此方法可能會引發(fā)異常(即Security Exception)。

Syntax:

句法:

boolean isFile(){}

Parameter(s):

參數(shù):

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

我們不會在File方法中將任何對象作為參數(shù)傳遞。

Return value:

返回值:

The return type of this method is Boolean i.e. it returns true then in that case file is specified by abstract file path is a file else returns false so the file is specified is not a file.

此方法的返回類型為Boolean,即返回true,則在這種情況下,文件由抽象文件路徑指定為文件,否則返回false,因此指定的文件不是文件。

Java程序演示isFile()方法的示例 (Java program to demonstrate example of isFile() 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 ToCheckFile {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\\JavaArticles");// By using isFile() is used to check whether the filepath // is a file or not. It returns true because given filepath is a file.if (file1.isFile())System.out.println("This filepath " + " " + file1.getAbsolutePath() + " " + "is a file");elseSystem.out.println("This filepath " + " " + file1.getAbsolutePath() + " " + "is not a file");// By using isFile() is used to check whether the filepath // is a file or not. It returns false because given filepath // is not a file .if (file2.isFile())System.out.println("This filepath " + " " + file2.getAbsolutePath() + " " + "is a file");elseSystem.out.println("This filepath " + " " + file2.getAbsolutePath() + " " + "is not a file");} catch (Exception e) {System.out.println("An error occurred.");e.printStackTrace();}} }

Output

輸出量

D:\Programs>javac ToCheckFile.javaD:\Programs>java ToCheckFile This filepath C:\Users\computer clinic\OneDrive\Articles\myjava.txt is a file This filepath C:\Users\computer clinic\OneDrive\JavaArticles is not a file

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

總結(jié)

以上是生活随笔為你收集整理的Java File类boolean isFile()方法(带示例)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。