Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java file rename/move and inherited permissions  RSS feed

 
Shaun Brockhoff
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to move files from one folder to another on the same drive. I have tried using the java.io.File renameTo method and also the Google Guava Files.move method. Both of these methods will successfully copy the file, but when I look at the permissions they are not getting the inherited permissions, but instead retain the original permissions. If I do a copy and delete then the file does get the inherited permissions.

How can I do a file move in Java while keeping the inherited permissions (I would rather not do a copy/delete if possible since the files may be large)? Thanks

Shaun
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're seeing behaviour of the underlying operating system. It's not like Java or Guava is specifically setting any permissions, they are just accepting whatever the underlying operating system does with the permissions when a file is moved.
 
Shaun Brockhoff
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I think you're seeing behaviour of the underlying operating system. It's not like Java or Guava is specifically setting any permissions, they are just accepting whatever the underlying operating system does with the permissions when a file is moved.


Thanks. I looked some more into this and it looks like when you move using the GUI (windows) by either right click drag and drop and selecting move, or by cut and paste, it does a move and it takes on the correct permissions but if you use "move" via the command line then the behavior is the same as when I do it in Java where it does not get the permissions.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's an interesting difference, which I wouldn't have expected. But no doubt Java is using the same mechanisms as the command line when it moves a file.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!