Java 如何在intellij中更改文件的只读状态

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44265670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 01:27:17  来源:igfitidea点击:

How to Change Read-Only Status of Files in intellij

javaintellij-idea

提问by Harry Prn Dz

I have a Java project and I want to modify it in intellij but I can't do it because of this " read-only file "or "file is not writable", so how I can modify and execute it?

我有一个 Java 项目,我想在 intellij 中修改它,但由于这个“只读文件”“文件不可写”而无法修改,那么我该如何修改和执行它呢?

this is the problem

这就是问题

回答by Carlos Bernardes

To toggle read-only attribute of a file

切换文件的只读属性

Open file in the editor, or select it in the Project tool window. Do one of the following:

在编辑器中打开文件,或在项目工具窗口中选择它。执行以下操作之一:

On the main menu, choose File | Make File Read-Only, or File | Make File Writable.

在主菜单上,选择文件 | 使文件只读,或文件 | 使文件可写。

Click the lock icon in the Status bar.

单击状态栏中的锁定图标。

回答by H?vard Geithus

If IntelliJ IDEA is unable to change the file permissions using File | Make File Writable, then perhaps another user is owning that file, e.g. root (use this command to verify: ls -hal /path/to/File.java)

如果 IntelliJ IDEA 无法使用File |更改文件权限 make文件可写的话,或许另一个用户拥有该文件,如根(使用此命令来验证:ls -hal /path/to/File.java

If someone else owns it, for whatever reason, you can change the permissions yourself using the chowncommand in the terminal:

如果其他人拥有它,无论出于何种原因,您都可以在终端中使用chown命令自己更改权限:

sudo chown yourusername /path/to/File.java,

sudo chown yourusername /path/to/File.java,

where yourusernameis the same user that you used to launch Intellij IDEA.

yourusername您用于启动 Intellij IDEA 的同一用户在哪里。

回答by Long Nguyen

If you're using Mac. Follow bellow steps:

如果您使用的是 Mac。请按照以下步骤操作:

  1. Open that file by Finder
  2. Right click and select Get Info
  3. In that File Info window, select Sharing and Permissions, change Privilegeas you expected. Before changing, you would remember unlocking your change permission by click on a Locker Iconat bottom right.
  1. 用 Finder 打开那个文件
  2. 右键单击并选择 Get Info
  3. 在该文件信息窗口中,选择Sharing and PermissionsPrivilege按预期进行更改。在更改之前,您会记得通过单击右下角的 a 来解锁您的更改权限Locker Icon

enter image description here

在此处输入图片说明

回答by Carlos Murray

On your top-left corner in the drop-down where you have Tests,Production,Problems switch/choose from Project or any other directory you've choosen to Packages, you'll have your packages editable, files in the Project folder are not editable although they end with .classextension.

在下拉菜单的左上角,您可以从 Project 或您选择的任何其他目录中切换/选择 Tests、Production、Problems 到 Packages,您将可以编辑您的包,Project 文件夹中的文件不是可编辑,尽管它们以.class扩展名结尾。

回答by tryingsohard

I was just having this issue and I finally figured out where I was going wrong.

我刚刚遇到这个问题,我终于弄清楚我哪里出错了。

Over an hour of suggestions from Google didn't help. It turns out I was on files selected in the -out > production > MyPath folder instead of the -src folder in my project sidebar. Selecting the -scr > MyClass file allows me to do what I want to do.

来自谷歌的一个多小时的建议没有帮助。事实证明,我是在 -out > production > MyPath 文件夹中选择的文件,而不是项目侧栏中的 -src 文件夹。选择 -scr > MyClass 文件允许我做我想做的事情。

回答by Dato Gogshelidze

For Mac, it definitely works:

对于 Mac,它绝对有效:

sudo chmod -R 777 /YourDirectory

sudo chmod -R 777 /YourDirectory

回答by Manish Chauhan

This error appears when the other user has created those files.
1. Right click on the file or folder to be deleted.
2. Choose reveal in folder option.
3. Delete the file and enter the password.
4. Files will be deleted.

当其他用户创建这些文件时会出现此错误。
1. 右键单击​​要删除的文件或文件夹。
2. 选择在文件夹选项中显示。
3. 删除文件并输入密码。
4. 文件将被删除。