CentOS7下Sublime Text3保存Java文件提示权限拒绝问题求助
Hey there! Let's work through this issue together. First, I spotted a couple of critical typos in your Java code that'll cause errors even after fixing the permission problem—let's get those out of the way first, then tackle the saving issue.
Step 1: Fix Your Java Code
Java is case-sensitive, so these two mistakes will prevent your code from compiling:
stringshould be uppercaseString(the official Java class name)system.out.printlnshould beSystem.out.println(the standard output class is capitalized)
Here's the corrected code:
package com.javatools.git; public class FirstSource { public static void main(String[] args) { System.out.println("Hello World"); } }
Step 2: Resolve the "Permission Denied" Error
The error means Sublime Text doesn't have write access to the ~/git_tutorial/git_repo/ directory. Try these solutions in order:
Option 1: Grant Write Permissions to the Directory
Give your user account write access to the target folder with this terminal command:
chmod -R u+w ~/git_tutorial/git_repo/
u+w: Adds write permission specifically for your user account-R: Applies the change recursively to all files and subfolders inside the directory
Option 2: Change the Directory's Owner (If Needed)
If the directory was created by another user (like root), change its owner to your user account to gain full control:
sudo chown -R $USER:$USER ~/git_tutorial/git_repo/
This ensures you can read, write, and modify anything inside the folder.
Option 3: Temporary Fix (Use Sudo to Open Sublime)
For a quick temporary solution (not recommended for regular use, as it can cause permission conflicts), open Sublime with root privileges:
sudo subl
Then save your file from this elevated instance of Sublime.
Once you've fixed the permissions and the code, you should be able to save the file successfully and compile your first Java program!
内容的提问来源于stack exchange,提问作者bbjoony

