Java文件類boolean canExecute()方法(帶示例)

文件類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.

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

  • 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則表示文件可以由文件路徑表示的應用程序執行,或者換句話說,文件已經存在要執行,并且返回false表示文件不存在這意味著不允許應用程序執行文件。

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

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

Syntax:

句法:

    boolean canExecute(){
}

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 if the file already exists and allowed to execute the file which is denoted by the abstract file path returns false otherwise.

此方法的返回類型為Boolean,即如果文件已經存在并且允許執行該文件(由抽象文件路徑表示),則返回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");
else
System.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");
else
System.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 ExecuteFile
This 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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379841.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379841.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379841.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

python安全攻防---scapy使用

導入scapy包 from scapy.all import *構造包 a Ether()/IP(dst114.114.114.114)/TCP(dport80)/應用層數據我們如果記不得每個包的選項使,可以使用show()來查看 print(a.show())發送包 sr(IP(dst‘192.168.1.0/24’)/TCP(dport(1,65535)), timeout2) &#xff1…

唉!

學習到后面時,再返回看了一下前面學過的,發現以前學過,看不懂的東西現在能看懂了…… !不過 為什么在剛學時就是不懂,這樣 不就老是慢一拍嗎?唉!!轉載于:https://www.cnblogs.com/ni…

Java—— TCP協議(相關代碼實現以及相關優化)

代碼運行的時候先運行服務端,然后在運行客戶端 * TCP協議:* 1,客戶端* 創建Socket連接服務器(指定IP地址,端口號)通過IP地址找到對應的服務器* 調用Socket的getInputStream()和getOutputStream()方法獲取和服務器端相連…

什么是adsense 想通過廣告掙錢的看過來

Adsense的含義Google AdSense是由Google公司推出的針對網站主(簡稱發布商)的一個互聯網廣告服務。AdSense是個合成詞。其中ad是“廣告”之意,sense是“感知”之意,綜合起來的意思就是相關廣告。Google通過程序來分析網站的內容&am…

Java GregorianCalendar getTimeZone()方法與示例

GregorianCalendar類的getTimeZone()方法 (GregorianCalendar Class getTimeZone() method) getTimeZone() method is available in java.util package. getTimeZone()方法在java.util包中可用。 getTimeZone() method is used to return the time zone for this GregorianCale…

python安全攻防---信息收集---ICMP主機探測 以及optionparser的使用

0x01 基礎概念 ICMP(Internet control Message Protocal)Internet報文協議,是TCP/IP的一種子協議,屬于網絡層協議,其目的是用于在IP主機、路由器之間傳遞控制信息 0x02 程序 程序 # -*- coding:utf-8 -*- from sca…

PHP文件系統-文件下載

一、網頁請求和響應的過程 請求: 1. HTTP 1.1 協議 版本 2. 頭信息,請求的ip,其他 3. 你請求的表單信息, 你提交給服務器的信息 http://localhost/one.php?aabbb&cccdd 響應: 1. 狀態 200 ok 404 頁面沒找到 2. 響應頭信息&a…

Java——網絡編程練習

練習一(黑馬程序員面試題):客戶端向服務器寫字符串(鍵盤錄入),服務器(多線程)將字符串反轉后寫回,客戶端再次讀取到的是反轉后的字符串 相關代碼如下: package com.wsq.test;import java.io.BufferedReader; import java.io.Buf…

第一章 基礎知識---1.4Crack小實驗--復現

0x01 程序及其編譯環境 程序如下&#xff0c;功能&#xff1a;我們必須輸入正確的密碼1234567才能得到密碼驗證的確認&#xff0c;跳出循環。否則程序提示密碼錯誤再次輸入。 #include <stdio.h>#define PASSWORD "1234567"int verify_password(char* passwo…

.net中調用exchange服務器發郵件

普通的郵件, 用System.Net.Mail 類 或 System.Web.Mail 類 處理即可, 但是Exchange Server 環境下, 這兩個類起不了作用-------至少目前我看到的情況如此. 整個過程如下: 1. 先添加COM 引用 "Microsoft CDO for Windows 2000 Library" .2. 發送郵件的代碼: CDO.Messa…

Java Double類doubleToLongBits()方法與示例

Double類doubleToLongBits()方法 (Double class doubleToLongBits() method) doubleToLongBits() method is available in java.lang package. doubleToLongBits()方法在java.lang包中可用。 doubleToLongBits() method follows IEEE 754 double floating-point standards and …

Firefox(火狐瀏覽器)彩蛋

①在地址欄上輸入&#xff1a; about:mozilla ②在地址欄上輸入&#xff1a; about:robots ③在地址欄上輸入&#xff1a; www.figma.com/404/ ④地址欄上輸入&#xff1a; chrome://global/content/alerts/alert.xul

jquery.history插件在ie中失效的問題

hash標志中不能有? ff中不存在這個問題。 轉載于:https://www.cnblogs.com/xyun/archive/2008/12/01/1345188.html

Java——反射(Class.forName()讀取配置文件舉例).

榨汁機(Juicer)榨汁機的案例&#xff1a; 分別有水果(Fruit),蘋果(Apple)&#xff0c;香蕉(Bananal)&#xff0c;橘子(Orange),榨汁(squeeze) 要求&#xff1a; 榨出不同的水果汁來喝 //一般方法求解 package com.testl;public class Text1 {public static void main(Strin…

java 根據類名示例化類_Java類類getEnclosingClass()方法及示例

java 根據類名示例化類類的類getEnclosingClass()方法 (Class class getEnclosingClass() method) getEnclosingClass() method is available in java.lang package. getEnclosingClass()方法在java.lang包中可用。 getEnclosingClass() method is used to return recent or im…

C++:cin.getline

轉&#xff1a;百度百科 http://baike.baidu.com/view/2383876.htm cin.getline 此函數是按行讀取,其語法為:cin.getline(字符指針,字符個數N,結束符); 功能是&#xff1a;一次讀取多個字符(包括空白字符&#xff09;&#xff0c;直到讀滿N-1個&#xff0c;或者遇到指定的結束符…

端口復用和重映射--STM32F103

什么是端口復用&#xff1f; STM32中有很多內置外設&#xff0c;這些外設的引腳都是與GPIO復用的&#xff0c;什么時候復用呢&#xff1f;就是當一個GPIO作為內置外設引腳使用時&#xff0c;就叫做復用。比如串口1的發送接收引腳是PA9&#xff0c;PA10&#xff0c;當PA9&#…

考研數學

眼前儼然一副冬的氣象&#xff0c;伴隨氣溫的驟降&#xff0c;考研復習也進入異常緊張的階段。在考試前這兩個月里&#xff0c;考生如何復習數學&#xff0c;成績還可以有所提高。萬學?海文數學教研組針對沖刺階段數學復習歸納總結以下復習經驗和建議&#xff0c;供大家參考。…

一個很好的自學網站~推薦一下

http://www.51zxw.net/study.asp?vip15746908

[轉]Ubuntu遠程桌面登陸

原文地址&#xff1a;http://www.cnblogs.com/xdzone/archive/2011/03/10/1979644.html 1.xp下默認的遠程桌面協議是rdp&#xff0c;默認端口3389&#xff0c;而ubuntu用的時vnc&#xff1a;默認端口5900 2.首先被訪問的主機&#xff08;windows/linux&#xff09;都要設置為允…