canExecute()函數是Java中File類的一部分。此函數確定程序是否可以執行由抽象路徑名表示的指定文件。如果文件路徑存在並且允許應用程序執行文件,則此方法將返回true。否則它將返回false。

函數簽名:

public boolean canExecute()

用法:

file.canExecute();

參數:該函數不接受任何參數。

返回值:此函數返回一個布爾值,表示是否可以執行指定的文件。

異常:如果對文件的讀取訪問被拒絕,則此方法將引發Security Exception

以下示例程序旨在說明canExecute()函數的用法:

範例1:文件“F:\\program.txt”是F:目錄中的現有文件,並且允許該程序執行該文件的權限。

// Java program to demonstrate

// canExecute() method of File class

import java.io.*;

public class solution {

// Driver Code

public static void main(String args[])

{

// Get the file to be executed

File f = new File("F:\\program.txt");

// Check if this file

// can be executed or not

// using canExecute() method

if (f.canExecute()) {

// The file is can be executed

// as true is returned

System.out.println("Executable");

}

else {

// The file is cannot be executed

// as false is returned

System.out.println("Non Executable");

}

}

}

輸出:

Executable

範例2:文件“F:\\program1.txt”不存在,我們將嘗試檢查該文件是否可執行。

// Java program to demonstrate

// canExecute() method of File class

import java.io.*;

public class solution {

// Driver Code

public static void main(String args[])

{

// Get the file to be executed

File f = new File("F:\\program1.txt");

// Check if this file

// can be executed or not

// using canExecute() method

if (f.canExecute()) {

// The file is can be executed

// as true is returned

System.out.println("Executable");

}

else {

// The file is cannot be executed

// as false is returned

System.out.println("Non Executable");

}

}

}

輸出:

Non Executable

注意:程序可能無法在在線IDE中運行。請使用離線IDE並設置文件的路徑。

java file.canexecute_Java File canExecute()用法及代碼示例相关推荐

  1. java中getfield_Java Class getField()用法及代碼示例

    java.lang.Class類的getField()方法用於獲取此類的指定字段,該字段是公共字段及其成員.該方法以Field對象的形式返回此類的指定字段. 用法: public Field getF ...

  2. java版本的getorcreate_Java ContainerUtil.getOrCreate方法代碼示例

    本文整理匯總了Java中com.intellij.util.containers.ContainerUtil.getOrCreate方法的典型用法代碼示例.如果您正苦於以下問題:Java Contai ...

  3. java cl 規格_Java JavaCL類代碼示例

    本文整理匯總了Java中com.nativelibs4java.opencl.JavaCL類的典型用法代碼示例.如果您正苦於以下問題:Java JavaCL類的具體用法?Java JavaCL怎麽用? ...

  4. java findpage 方法_Java Strings.isNotBlank方法代碼示例

    本文整理匯總了Java中de.invesdwin.util.lang.Strings.isNotBlank方法的典型用法代碼示例.如果您正苦於以下問題:Java Strings.isNotBlank方 ...

  5. java try finally connectoin close_Java SocketChannel類代碼示例

    本文整理匯總了Java中io.netty.channel.socket.SocketChannel類的典型用法代碼示例.如果您正苦於以下問題:Java SocketChannel類的具體用法?Java ...

  6. java document to xml_Java Document.asXML方法代碼示例

    本文整理匯總了Java中org.dom4j.Document.asXML方法的典型用法代碼示例.如果您正苦於以下問題:Java Document.asXML方法的具體用法?Java Document. ...

  7. java getitem方法_Java Datasource.getItem方法代碼示例

    本文整理匯總了Java中com.haulmont.cuba.gui.data.Datasource.getItem方法的典型用法代碼示例.如果您正苦於以下問題:Java Datasource.getI ...

  8. randint用法 python_Python randint()用法及代碼示例

    randint()是Python3中隨機模塊的內置函數.隨機模塊提供對各種有用功能的訪問,其中一個功能可以生成隨機數,即randint().句法: randint(start, end) 參數: (s ...

  9. python中的os abort_Python os.abort()用法及代碼示例

    Python中的OS模塊提供了與操作係統進行交互的功能.操作係統屬於Python的標準實用程序模塊.該模塊提供了使用依賴於操作係統的功能的便攜式方法. os.abort()Python中的方法用於生成 ...

最新文章

  1. python经典好书-有哪些 Python 经典书籍?
  2. struts2官方 中文教程 系列一:创建一个struts2 web Application
  3. MM模块常用T-code
  4. JdbcTemplate类中的execute方法
  5. php提交飞信,php发送飞信消息
  6. java子类代码块_java中父类子类静态代码块、构造代码块执行顺序
  7. 同一台服务器上部署多个Tomcat的配置修改方法
  8. 【Uva 11280 飞到弗雷德里顿】
  9. en55032最新标准下载_欧盟新EMC标准EN55032
  10. HTML | 分享几个HTML邮件样式模板
  11. RYYB图像格式学习
  12. Vue安装教程(保姆级详细教程)
  13. 冰点还原界面无法呼出如何解决
  14. 为什么计算机二级查成绩显示验证码错误,我明明输入的是正确的验证码,为何电脑总显示验证码错误呢?...
  15. 2019 大前端是什么,我们该学什么?
  16. 游戏3d模型如何放到计算机中,三维建模技术在三维游戏中的应用
  17. SAP ABAP 解析 excel 文件的函数 TEXT_CONVERT_XLS_TO_SAP 单步执行分析
  18. 遍历二维数组(从外向内绕圈)
  19. 5,10,15,20-四(3,5-二甲氧基苯基)卟啉((TdmPP)H2)/2-硝基-5,10,15,20-四(3,5-二甲氧基苯基)卟啉铜(NO2TdmPP)Cu)齐岳供应
  20. 攻防世界-pwn-forgot

热门文章

  1. [svn] linux 下svn服务器的搭建
  2. Linux -- ***检测系统(IDS)介绍及应用(1)
  3. ajax jquery return没有返回值
  4. 使用PHP读取和创建txt,doc,xls,pdf类型文件
  5. 经典网页设计:15个使用网格系统的精美网站作品
  6. 使用Azure SDK 1.4.1中的Web Deploy
  7. Linux下文本处理命令的使用
  8. 在Android开发中,有哪些好的内存优化方式?如何避免 Out Of Memory(OOM) ?
  9. 最大字段和 冲出暴力枚举
  10. C++/STL Bitset (转)