「java设置文件权限」java方法默认权限

博主:adminadmin 2022-11-28 16:46:08 65

今天给各位分享java设置文件权限的知识,其中也会对java方法默认权限进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

Java代码更改 Linux 文件访问权限有时不起作用?

你说的更改权限为640和你后面的代码并不一致,理论上应该有直接以数字为参数的方法吧?

还有注意检查运行java代码的当前用户是哪个?因为权限涉及到当前用户。

如何用java实现 禁止指定文件的修改、删除

JDK 1.6 File 有这个方法

setExecutable

public boolean setExecutable(boolean executable,

boolean ownerOnly)设置此抽象路径名的所有者或所有用户的执行权限。

参数:

executable - 如果为 true,则设置允许执行操作的访问权限;如果为 false,则不允许执行操作。

ownerOnly - 如果为 true,则执行权限只适用于所有者的执行权限;否则适用于所有用户。如果底层文件系统不能区分所有者执行权限与其他执行权限,那么无论该参数为何值,执行权限将适用于所有用户。

返回:

当且仅当操作成功时返回 true。如果用户不具有更改此抽象路径名访问权限的权限,那么操作将失败。如果 executable 为 false,并且底层文件系统不实现执行权限,那么操作也将失败。

抛出:

SecurityException - 如果安全管理器存在且其 SecurityManager.checkWrite(java.lang.String) 方法拒绝对文件进行写访问。

从以下版本开始:

1.6

JDK 1.5 的话 有一个设置 readonly的方法 也就是只读

File file = new File("e:/temp/123.txt");//文件路径

file.setReadOnly();//设置只读

希望对你有所帮助

linux环境下 Java生成文件并赋予权限的问题

java 处理一些通用的权限

1、在java中,文件的权限对于不同的操作系统有不同的权限。 java 处理一些通用的权限。

2、检查文件是否允许:

file.canExecute(); – return true, file is executable; false is not.

file.canWrite(); – return true, file is writable; false is not.

file.canRead(); – return true, file is readable; false is not.

3、设置文件权限:

file.setExecutable(boolean); – true, allow execute operations; false to disallow it.

file.setReadable(boolean); – true, allow read operations; false to disallow it.

file.setWritable(boolean); – true, allow write operations; false to disallow it.

4、在*nix系统中,你可能需要配置更加明确的文件权限,如设置某个文件的权限为777.但是,java IO类没有相关方法。

Runtime.getRuntime()。exec("chmod 777 file");

linux环境下 Java生成文件并赋予权限的问题,求解?

java 处理一些通用的权限

1、在java中,文件的权限对于不同的操作系统有不同的权限。 java 处理一些通用的权限。

2、检查文件是否允许:

file.canExecute(); – return true, file is executable; false is not.

file.canWrite(); – return true, file is writable; false is not.

file.canRead(); – return true, file is readable; false is not.

3、设置文件权限:

file.setExecutable(boolean); – true, allow execute operations; false to disallow it.

file.setReadable(boolean); – true, allow read operations; false to disallow it.

file.setWritable(boolean); – true, allow write operations; false to disallow it.

4、在*nix系统中,你可能需要配置更加明确的文件权限,如设置某个文件的权限为777.但是,java IO类没有相关方法。

Runtime.getRuntime()。exec("chmod 777 file");

想保存文件在java说没有管理权限,怎么设置?

Program Files文件夹写文件需要管理员权限。一般不用来存源代码。

或者你用管理员方式打开你的ide就没问题。

java中怎么设置文件权限?

import java.io.IOException;/××只能给当前用户赋予对该文件的权限,调用createNewFile()方法默认的权限是644.

×/public class FilePermission{public static void main( String[] args ){try {File file = new File("/home/test3.txt");

if (file.createNewFile()){

System.out.println("File is created!");

//Runtime.getRuntime().exec("chmod 777 /home/test3.txt");

file.setExecutable(true);//设置可执行权限

file.setReadable(true);//设置可读权限

file.setWritable(true);//设置可写权限

System.out.println("is execute allow : " + file.canExecute());

System.out.println("is read allow : " + file.canRead());

System.out.println("is write allow : " + file.canWrite());}else{System.out.println("File already exists.");}

java设置文件权限的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java方法默认权限、java设置文件权限的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-28,除非注明,否则均为首码项目网原创文章,转载请注明出处。