Trying to write a file (text), but getting (permission denied)
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Trying to write a file (text), but getting (permission denied)
I have a Java label printing app deployed on JBoss 7 on a Linux OS server. The app formats / writes a text file with user keyed data and then sends the file to a printer. On my workstation, using the same version of JBoss 7, this works every time. On the Linux server, I get "java.io.filenotfoundexception filename.txt (permission denied)" every time. This continues despite the fact that I changed the folder permissions to 777. At this point, I'm not even sure whether it's JBoss or Linux that won't let the app create this file, but I've been checking forums, googling the error message, and reading user guides without finding any answers, so far.
Are you sure the file is being created in the directory that you think it's going in? Do you see the full path to the file in the exception? Do you have access to the source to dump out the file name with the full path before it attempts to write it?
It is on my PC. What I see in the exception is exactly the path I specified in my code. I also have a log message, but it shows the same thing as the exception.
If I specify no path (just filename), on my PC the file gets written to the JBoss bin folder; but on the server I still get (permission denied). Since both places have the same version installed (7.1.1), I would expect the same result. I've also tried several "relative" paths (like "../standalone/tmp/", which absolutely does exist in JBoss 7). On my PC, this works and the file is written to the specified location, but no joy on the Linux server. Does Linux compute paths differently from Windows?
Here's the most likely issue you're encountering: JBoss has been probably installed by an admin user on the server machine, but the user which launched it hasn't got the same permission as the one who installed it, so there's no way any application launched from it can alter the JBoss installation contents. This is perfectly normal behavior, as server software is often launched as an unprivileged user to minimize some intrusion risks.
Given that the text file seems to be only a temporary file, you should exploit the File.createTempFile(..) method of the File class to let the Java VM choose a "safe" path where you can write temporary files and the like.
Last edited by 414N; 08-07-2012 at 07:31 AM.
Reason: removed a type
Trying to write text file permission problem solved
I'm happy to report a solution to this issue. Apparently, Linux resolves "relative" addressing in a different way than Windows. Following a suggestion from a co-worker, the app now retrieves a JBoss system property and sets an "absolute" filepath using that value plus the filename.
Many thanks for your time and attention.
Sincerely, javaman
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.