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

歡迎訪問 生活随笔!

生活随笔

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

java

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

發(fā)布時(shí)間:2023/12/1 java 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java文件类boolean canExecute()方法(带示例) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文件類boolean canExecute() (File Class boolean canExecute())

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

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

  • This method is used to execute the file and the file is represented by the abstract file path or in other words this method is used to test whether the application can execute the file or not.

    此方法用于執(zhí)行文件,并且文件由抽象文件路徑表示,或者換句話說,該方法用于測試應(yīng)用程序是否可以執(zhí)行文件。

  • The return type of this method is Boolean i.e. it returns true or false if true that means file can be executed by the application which is represented by the file path or in other words file already exists to execute and returns false that means file does not exist it means the application is not allowed to execute the file.

    此方法的返回類型為布爾值,即返回true或false,如果為true則表示文件可以由文件路徑表示的應(yīng)用程序執(zhí)行,或者換句話說,文件已經(jīng)存在要執(zhí)行,并且返回false表示文件不存在這意味著不允許應(yīng)用程序執(zhí)行文件。

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

    如果未授予文件執(zhí)行訪問權(quán)限,則此方法可能引發(fā)異常(即Security Exception)。

Syntax:

句法:

boolean canExecute(){}

Parameter(s):

參數(shù):

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

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

Return value:

返回值:

The return type of this method is Boolean i.e. it returns true if the file already exists and allowed to execute the file which is denoted by the abstract file path returns false otherwise.

此方法的返回類型為Boolean,即如果文件已經(jīng)存在并且允許執(zhí)行該文件(由抽象文件路徑表示),則返回true,否則返回false。

Java程序演示canExecute()方法的示例 (Java program to demonstrate example of canExecute() 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 ExecuteFile {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\\java.txt");// By using canExecute() is allowed to execute // the file if file is already exists and // it returns true if file is executable else false returns.if (file1.canExecute())System.out.println("This file " + file1.getName() + " " + "is executable");elseSystem.out.println("This file " + file1.getName() + " " + "is not executable");// By using canExecute() is not allowed to execute // the file because this file is not already exists // and it returns false.if (file2.canExecute())System.out.println("This file " + file2.getName() + " " + "is executable");elseSystem.out.println("This file " + file2.getName() + " " + "is not executable");} catch (Exception e) {System.out.println("An error occurred.");e.printStackTrace();}} }

Output

輸出量

D:\Programs>javac ExecuteFile.java D:\Programs>java ExecuteFileThis file C:\Users\computer clinic\OneDrive\Articles\myjava.txt is not executable This file C:\Users\computer clinic\OneDrive\Articles\java.txt is not executable

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

總結(jié)

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

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