Java文件类boolean setExecutable(boolean exec_file,boolean owner_access)方法,带示例

文件类boolean setExecutable(boolean exec_file,boolean owner_access) (File Class boolean setExecutable(boolean exec_file , boolean owner_access))

  • This method is available in package java.io.File.setExecutable(boolean exec_file , boolean owner_access).

    软件包java.io.File.setExecutable(boolean exec_file,boolean owner_access)中提供了此方法。

  • This method is used to set the access permission to owner's or everybody's to execute the file.

    此方法用于将所有者或所有人的访问权限设置为执行文件。

  • This method accepts two parameters the first parameter is for file access and another parameter is for file is accessible by owner only or everybody's (i.e. If we pass true as a first parameter that means file is accessible else false file is not accessible and If we pass true as a second parameter that means file is accessible by owner's only else false that's means file is accessible to everybody's).

    此方法接受两个参数,第一个参数用于文件访问,另一个参数用于文件访问,只有所有者或所有人都可以访问(即,如果将true作为第一个参数传递,则意味着文件可访问,否则,将无法访问错误文件;如果传递作为第二个参数,则为true,表示文件只能被所有者访问;否则为false,表示每个人都可以访问文件)。

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

    如果未提供文件写入权限,则此方法可能会引发异常(即Security Exception)。

Syntax:

句法:

    boolean setExecutable(Boolean exec_file , boolean owner_access){
}

Parameter(s):

参数:

We pass two objects as a parameter in the method of the File i.e exec_file(Executable file ) and owner_access( File is executable by the owner or everybody's).

我们将两个对象作为参数传递给File的方法,即exec_file(Executable file)和owner_access(文件可由所有者或所有人执行)。

Return value:

返回值:

The return type of this method is Boolean if it returns true so the file is executable and else returns false file is not executable.

如果此方法返回true,则该方法的返回类型为Boolean ,因此该文件是可执行的,否则返回false不可执行的文件。

Java程序演示setExecutable()方法的示例 (Java program to demonstrate example of setExecutable() 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 ExecutableFileClass {
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 setExecutable(true , true)  is allowed 
// to execute the file by the owner only 
// [i.e. First true is for whether file is executable or not 
// (i.e. true means it is executable) and Second true is 
// for whether file is accessible by owner or everbody's
// (i.e. true means file is executable by owner only) ]
if (file1.setExecutable(true, true))
System.out.println("This file " + file1.getName() + " " + "is executable  by the owner only");
else
System.out.println("This file " + file1.getName() + " " + "is not executable");
// By using setExecutable(true , false)  is allowed 
// to execute the file by the everybody's 
// [i.e. First true is for whether file is executable or not 
// (i.e. true means it is executable) and Second true is 
// for whether file is accessible by owner or everybody's 
// (i.e. false means file is executable by everybody's) ]
if (file2.setExecutable(true, false))
System.out.println("This file " + file2.getName() + " " + "is executable by everybody's");
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 ExecutableFileClass.java
D:\Programs>java ExecutableFileClass
This file myjava.txt is executable  by the owner only
This file myjava1.txt is executable by everybody's

翻译自: https://www.includehelp.com/java/file-class-boolean-setexecutable-boolean-exec_file-boolean-owner_access-method-with-example.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/376992.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

OLTP 系统和 OLAP 系统的核心设计思想

关于 OLTP 系统和 OLAP 系统的核心设计思想 数据存储系统的关于查询的典型操作: -- 第一种需求: 根据 key(1) 找 value(name,age), 单点查询 select name, age from student where id 1; stu…

虚拟机

vt-x 虚拟技术的硬盘支持。想像成“硬解码”的东东。不是装虚拟机必须的,但有它效果会好些。 vt-x检测工具:securable.exe 下载地址:http://pan.baidu.com/s/1kTBOvzD Hardware Virtualization选项: no [CPU和BIOS都不支持VT] loc…

算法(转)

欢迎自荐和推荐链接。 算法 优秀博客推荐:各种数据结构与算法知识入门经典(不断更新)基本算法 贪心算法:贪心算法 作者:独酌逸醉 贪心算法精讲 作者:3522021224 递归和分治:递归与分治策略 …

sjf调度算法_如何通过静态方法预测SJF调度中未来过程的突发时间?

sjf调度算法In SJF Scheduling, CPU is assigned to the process having the smallest burst time but it can not be implemented practically, because we dont know burst time of the arrived processes in advance. 在SJF Scheduling中 ,将CPU分配给具有最短突…

flask 知识点总结

request对象的常用属性具体使用方法如下:request.headers, request.headers.get(If-None-Match)request.json, request.json[value] 或 request.json.get(detail_msg, "")request.args, request.args.get(limit, 10)来获取query parametersrequest.form, request.for…

Postgresql中的hybrid hash join(无状态机讲解)

hybrid hash join hybrid hash join是基于grace hash join 的优化。 在postgresql中的grace hash join 是这样做的:inner table太大不能一次性全部放到内存中,pg会把inner table 和outer table按照join的key分成多个分区,每个分区(有一个inn…

末日中的黎明

哈哈, 今天是2012-12-21,传说中的世界末日,不过现在看来,一切都是空的。。。 在这个容易记忆的日子里,我的博客开通了。他将伴随我以后的学习开发,期望我能充分利用博客,帮我养成常总结、常记笔…

使用numpy.tanh()打印矢量/矩阵元素的双曲正切值 使用Python的线性代数

Prerequisite: 先决条件: Defining a Vector 定义向量 Defining a Matrix 定义矩阵 Numpy is the library of function that helps to construct or manipulate matrices and vectors. The function numpy.tanh(x) is a function used for generating a matrix / v…

Mahout kmeans聚类

Mahout K-means聚类 一、Kmeans 聚类原理 K-means算法是最为经典的基于划分的聚类方法,是十大经典数据挖掘算法之一。K-means算法的基本思想是:以空间中k个点为中心进行聚类,对最靠近他们的对象归类。通过迭代的方法,逐次更新各聚…

Web项目中获取SpringBean——在非Spring组件中获取SpringBean

最近在做项目的时候我发现一个问题:Spring的IOC容器不能在Web中被引用(或者说不能被任意地引用)。我们在配置文件中让Spring自动装配,但并没有留住ApplicationContext的实例。我们如果希望在我们的项目中任何位置都能拿到同一个ApplicationContext来获取…

postgresql对于HashJoin算法的Data skew优化与MCV处理

Data skew 很好理解,即数据倾斜。现实中的数据很多都不是正态分布的,譬如城市人口,东部沿海一个市的人口与西部地区一个市地区的人口相比,东部城市人口会多好几倍。 postgresql的skew的优化核心思想是"避免磁盘IO"。 优…

JavaScript | 创建对象并通过JavaScript函数在表中显示其内容

In this example, we created an object named employee with id, name, gender, city, and salary and assigned and displaying the values in the table using JavaScript function. 在此示例中,我们创建了一个名为employee的对象,其对象为id &#x…

基于socket的简单文件传输系统

【实验目的及要求】 在 Uinx/Linux/Windows 环境下通过 socket 方式实现一个基于 Client/Server 文件传输程序。 【实验原理和步骤】 1. 确定传输模式:通过 socket 方式实现一个基于 Client/Server 或 P2P 模式的文件传输程序。 2. 如果选择的是 Client/Server 模式的文件传输…

《GPU高性能编程-CUDA实战》中例子头文件使用

《GPU高性能编程-CUDA实战(CUDA By Example)》中例子中使用的一些头文件是CUDA中和C中本身没有的,需要先下载这本书的源码,可以在:https://developer.nvidia.com/content/cuda-example-introduction-general-purpose-g…

mcq 队列_人工智能| AI解决问题| 才能问题解答(MCQ)| 套装1

mcq 队列1) Which of the following definitions correctly defines the State-space in an AI system? A state space can be defined as the collection of all the problem statesA state space is a state which exists in environment which is in outer spaceA state sp…

Postgresql的HashJoin状态机流程图整理

状态机 可以放大观看。 HashJoinState Hash Join运行期状态结构体 typedef struct HashJoinState {JoinState js; /* 基类;its first field is NodeTag */ExprState *hashclauses;//hash连接条件List *hj_OuterHashKeys; /* 外表条件链表;list of …

Ajax和Jsonp实践

之前一直使用jQuery的ajax方法,导致自己对浏览器原生的XMLHttpRequest对象不是很熟悉,于是决定自己写下,以下是个人写的deom,发表一下,聊表纪念。 Ajax 和 jsonp 的javascript 实现: /*! * ajax.js * …

得到前i-1个数中比A[i]小的最大值,使用set,然后二分查找

题目 有一个长度为 n 的序列 A&#xff0c;A[i] 表示序列中第 i 个数(1<i<n)。她定义序列中第 i 个数的 prev[i] 值 为前 i-1 个数中比 A[i] 小的最大的值&#xff0c;即满足 1<j<i 且 A[j]<A[i] 中最大的 A[j]&#xff0c;若不存在这样的数&#xff0c;则 pre…

学习语言贵在坚持

学习语言贵在坚持 转自&#xff1a;http://zhidao.baidu.com/link?urlr2W_TfnRwipvCDLrhZkATQxdrfghXFpZhkLxqH1oUapLOr8jXW4tScbyOKRLEPVGCx0dUfIr-30n9XV75pWYfK给大家介绍几本书和别处COPY来的学习C50个观点 《Thinking In C》&#xff1a;《C编程思想》&#xff1b; 《The…

stl vector 函数_在C ++ STL中使用vector :: begin()和vector :: end()函数打印矢量的所有元素...

stl vector 函数打印向量的所有元素 (Printing all elements of a vector) To print all elements of a vector, we can use two functions 1) vector::begin() and vector::end() functions. 要打印矢量的所有元素&#xff0c;我们可以使用两个函数&#xff1a;1) vector :: b…