-1

I have written a java code to transfer images from one folder to another in java. I have set file permissions like:

file.setReadable(true, false);    
file.setExecutable(true, false);    
file.setWritable(true, false);  

But setWritable is returning false. Please help me.

Bob
  • 1,489
  • 1
  • 16
  • 28
Manju Kb
  • 51
  • 1
  • 8

1 Answers1

0

If setWritable(true, false) is returning false if the operation fails.

As the javadoc says:

The operation will fail if the user does not have permission to change the access permissions of this abstract pathname.

Find out why your application doesn't have permission, and you can then figure out what you need to do to fix the problem ... or that you can't fix it.

(Running the code as "the administrator" may or may not work. For instance, if your application is a service that is running on a system with SELinux in enforcing mode, then even "root" privilege won't let you override the rules set down by the SELinux policy files.)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • The images are stored in ubuntu server as a folders .I want to move that images from one folder to other.I used Runtime.getRuntime().exec("chmod 777 file");.Still i am facing the same issue.Here is the sample code i have posted as aanswer.please check it and let me know – Manju Kb Feb 10 '15 at 11:02
  • There are a variety of reasons that `chmod 777` might fail or rename might fail. And `chmod 777 file` won't work unless the name of the file is "file". – Stephen C Feb 10 '15 at 12:24
  • I think you need to read up on how Unix / Linux file access control works. For example *who* is permitted to change the access mode of a file. And what permissions are required on what in order to rename a file. – Stephen C Feb 10 '15 at 12:27
  • how to check the name of the file is "file" or not?@stephen – Manju Kb Feb 10 '15 at 12:49
  • @ManjuKb - That's not the point. The point is that you `chmod` command is WRONG ... unless the name of the file is always "file". – Stephen C Feb 10 '15 at 22:10
  • "chmod 777 " where you replace "" with the actual name of the file. – Stephen C Feb 18 '15 at 01:25