The article is a bit long, friends who are anxious to solve the problem can directly read the last part (3).
Solve java.nio.file.AccessDeniedException: /opt/jeecg-boot/upload
There is a problem with the download file of the project on these two lines. I debugged it locally and found that the file can be downloaded normally, indicating that it is not a code problem.
1. Check the error log
After looking at the corresponding error log of the server, the following error is reported:
java.nio.file.AccessDeniedException: /opt/jeecg-boot/upload
reason:
I searched the Internet and found that this exception was reported because the newly mounted hard disk directory did not have write permission. The hard disk of the previous server was not enough, and the hard disk path was mounted later.
2. Give file permissions
Go to the "/opt/jeecg-boot/" directory on the server and use the command: ll to check the permissions of the "upload" directory:
drwxr-xr-x 9 root root 176128 Jul 20 17:42 upload
1. Explanation of file information
Divided by [space], a total of seven columns of information are displayed, from left to right: permission, number of files, belonging user, belonging group, file size, creation date, file name
(1), authority
In the first column, the first digit indicates the file type, and the first digit here is [d]
[d]: folder
[-]: common file
[l]: link
[b]: block device file
[p]: pipeline file
[c]: character device file
[s]: socket file
[rwx]: second The -4 bit indicates the authority of the owner of this file, where the owner is the information in the third column, that is, root. r is read, w is write, and x is execute.
[rx]: Bits 5-7 indicate the permissions of users in the same group as the owner of this file. Here, the same group is the information in the fourth column, which is also root.
【rx】: Bits 8-10 indicate the permissions of other users.
(2), the number of hard links
The second column
For files: generally 1, indicating itself. The file can only be located by the command "cd absolute path of the file".
For the directory: at least 2, for the new folder, you can enter the directory through "cd absolute path of the directory" or "cd ..." in the directory.
For details about hard links, you can read this big brother's blog, click to jump .
(3), file owner
The third column, here is root.
(4), all groups of files
The fourth column is also root.
(5), file size
The fifth column, here is 176128.
(6) The date when the file was last modified
The sixth column, here is Jul 20 17:42.
(7), file name
The seventh and last column, here is upload.
For an introduction to file information, you can read this blog, click to jump .
2. Give permission to the target folder
Order:
chmod 777 /opt/jeecg-boot/
explain:
Read r: 4
Write w: 2
Execute x: 1
So the number 7: 7=4+2+1=r+w+x means it has read, write, and execute permissions; 6=4+2=r+w means it has Read, write permissions, and so on. The next time you modify the permission, you can change the corresponding number.
Here 777 is to allow the owner, other users in the same group, and users in different groups to have read, write, and execute permissions.
After granting folder permissions, you need to restart the server, otherwise the command will not take effect . I use this command to restart the server directly. The command is as follows:
reboot
Check the target directory again after restarting
drwxrwxrwx 9 root root 176128 Jul 20 17:42 upload
You can see that the folder permissions have been changed, and the error should be resolved after restarting.
3. Reading and writing are carried out in the file subdirectory, and the parent file directory permission is still reported as an error
If the read and write operations occur in a subdirectory of the target directory, the above command will still report the error, indicating that the subdirectory does not have corresponding permissions. Open the "upload" directory to view the subdirectory information:
drwxr-xr-x 6 root root 176128 Jul 16 11:23 img
You can see that the subdirectory still only has write and execute permissions, so you need to use this command:
chmod 777 -R /opt/jeecg-boot/
explain:
-R means that all subdirectories are included, and the whole command is to give read and write permissions to the "/opt/jeecg-boot/" directory and subdirectories.
Restart the server and check the "img" directory again
drwxrwxrwx 6 root root 176128 Jul 16 11:23 img
Now the problem should be solved.