giku93113 giku93113 - 18 days ago 4x
Linux Question

Getting permission denied in Java when reading a file (Linux)

Hello Everyone i recently moved to Ubuntu to work on a project.
I have to simply read from a file, using:

File root = new File(fileroot);
File sourceFile = new File(root,filename);

But when i run the application, i get:
error: error reading FilePath; FilePath (Permession denied).

(FilePath is the path where the file is located, i've hidden it for privacy purposes)

I guess is something due to the Operative System, because running the same code on Windows doesn't give me any error. Is there a way to solve this? I mean a way to get those permissions directly from Java or maybe changing them from terminal using commands?

Thanks in advance for your answer guys!


One way to do this is to navigate to the file and change the permission to allow every user to read the file. The easiest is via terminal:

chmod +r /path/to/file

To see all the different uses follow the link and learn about chmod.