I am trying to write to a file using a FileOutputStream in java. I am running ubuntu and I think the problem is with the permissions. Even though the error I receive says '(No such file or directory)' I am sure the path I am giving is right, since I can read from the same file with no issues. I am not very familiar with ubuntu write permissions but I think I need to set the mode with chmod -r on the root directory. However I am not sure of the exact command and the option of permission I should set.
Related
I have run a thread group in JMeter in GUI mode it is working and getting results, but while running same ThreadGroup.jmx file through terminal(Non GUI] mode,I am getting an error Couldn't load .jmx file.
Can anybody suggest me how to resolve the issue.
In linux using files is case sensitive, so use exact letters(as sampleThreadGroup.jmx)
Also make sure the file is saved in the correct folder
And check your user have permission to execute it (try chmod 777 for jmx file)
A weird question:
I am running eclipse on windows and I am trying to open a file with a hard coded path:
String inputFile = "C:/temp/abc.txt";
File folder = new File(inputFile );
When I run this I get error:
java.io.FileNotFoundException: C:/temp/abc.txt (The system cannot find the file specified)
I have local admin rights on this windows 10 machine. I have tried running Eclipse as a Administrator but it doesn't resolve the issue.
The only way I can get by is if I traverse to C:/temp/ in cygwin and do a chmod 777 * . Then my program is able to open the file okay.
The work around should be fine if I was just reading a simple file but I am also creating files from within my java project which it does successfully create but then when it comes to reading them it fails.
myFile.setReadable(true); // doesnt work either.
Is this some sort of windows permissions issue ? Could it be that cygwin has taken over some admin rights on the file system? I have tried stopping it but the issue persists. Or is this an eclipse setting?
Many Thanks,
-A
It was a windows permissions issue.
Right click on the folder -> Properties -> Security -> Edit -> Add -> Everyone.
I dont understand why I need to add every one if I am the local admin and I launched eclipse but frankly I dont care about the bizarre world of windows.
Thanks to all those who tried helping.
Cheers
check this.
Permission Denied: File Creation in Java
https://www.mkyong.com/java/how-to-set-the-file-permission-in-java/
I have jdk1.7.0_07 installed on server(linux). The file permission to ~/bin files are executable(755). However when I tried to execute,
$output = exec("/usr/java/jdk1.7.0_07/bin/java -version 2>&1");
echo $output;
It gives permission denied error, I have tried this,
$output = exec("java -version 2>&1");
echo $output;
Which gives command not found error. While checking my environment variables. I have succesfully added JAVA_HOME = /usr/java/jdk1.7.0_07 and for PATH = /usr/java/jdk1.7.0_07/bin
But,
When I run above mentioned PHP script it keeps giving me those permission denied or command not found error. Any personal experience or clue?
If you are running these commands from the command-line, you probably execute them with your own user permissions. However, when you execute these same commands via a PHP script in a web app, they will be executed with the Apach user (typically www-data) permissions. These means that you cannot rely on the command-line output to debug permission errors unless you can log in as the exact same user that runs your PHP script.
If your OS is CentOS it could come from SELinux.
root#ls:~# /usr/sbin/getenforce
Enforcing
root#ls:~# /usr/sbin/setenforce Permissive
root#ls:~# /usr/sbin/getenforce
Permissive
More detail in https://superuser.com/questions/455935/php-script-cant-run-bash-script-sh-permission-denied
It fixed the problem for me.
It seems you have 2 distinct problems:
If it gives you permission denied error when you give the full path to Java executable, then your permissions are probably incorrect. The most common cause is, somewhere along the path, Apache User (usually www-data) does not have read access. For instance, if www-data does not have read permission for jdk1.7.0_07 directory it can't see (or open) it's child directory called bin.
Regarding the path, it will not work unless permissions are correctly set. However, where did you set your environment PATH? Was it in the user profile?
I am running a webservice using glassfish server on Ubuntu. The problem is - it is required to access a directory outside of its shared resource. Presently it is giving an error saying "Permission Denied". I set a permission into server.policy too.
grant codeBase "/home/glassfish/glassfish/test/-" {
permission java.security.AllPermission;
};
But it seems not working.
I tried <property name="alternatedocroot_1" value="from=*.* dir=/home/glassfish/glassfish/test"/> , but it seems it is giving only reading permission. I need write permission also. So my question is how can I set the write permission ?
Thanks.
This is not a JavaSecurity problem so you shouldn't need to tweak anything in that regard.
FWIW our web-apps deployed to GF on various flavors of Windows write to directories which are outside of the 'Application' directory using File APIs. alternatedocroot pertains to GF serving static content using the DefaultServlet not to writing outside of the Application deployment directory.
On windows when you run as Service you have to be careful that the 'Run As' user has proper permissions to write to the target directory, on Unix you need to make sure the user set by your rc (init.d) scripts that runs asadmin.sh has permissions to read/write to the target directory.
I would double check the the user that the java process GF is running under has rwx permissions on the directory your are trying to write to. Make sure that user can write to the target folder. To test this you can su to the user and use the 'touch' command like so: touch /tmp/test and verify write permissions that way. Verify read permissions similarly by running 'ls -l /tmp/test' to make sure you can read it.
See what 'ps -ef | grep java' shows to verify the user running the GF java process. Additionally in your code try specifying a full path to the test file, eg. File test = new File("/tmp/test");
Are you running GF from an rc script or are you starting it using asadmin.sh from a shell prompt? If you are running an rc script check that your rc script is really running it as the user you expect it to be.
When I run code like this in Mac os:
Runtime.getRuntime.exec("open testFile.pdf");
the Mac OS will run Acrobat to open the local PDF file.
How can I do it, when the file is on a remote machine?
\\remoteHost\share\testFile.pdf
I try to do that like this:
Runtime.getRuntime.exec("open \\\\remoteHost\\share\\testFile.pdf");
but I failed.
Thanks!
Runtime.getRuntime().exec(String) just passes the String to the OS for it to handle it. So, if you want to run the command
open \\remoteHost\share\testFile.pdf
You have to pass it to exec(). Remember to escape the \ (replace every \ by \\)
Runtime.getRuntime().exec("open \\\\remoteHost\\share\\testFile.pdf");
Of course, the user running the program should have permissions in the remote machine. If you need to set another user, use the open program command line parameters.
I don't think it's possible to directly specify the path of an SMB share while using the open command. If you want to use open, you would have to mount that share as a local directory. See http://osxdaily.com/2009/09/24/access-and-mount-an-smb-share-via-command-line/ for an explanation.
A solution like that would be pretty fragile though. If you want a more reliable solution, I'd suggest using JCIFS (http://jcifs.samba.org/) to download the file locally and then use
Desktop.getDesktop().open(pdfFile);
to open the downloaded file.