Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File Permissions

 
Joe Pluta
Ranch Hand
Posts: 1376
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question was asked three years ago, and the answer was "you can't do that." I'm wondering if this has changed. Here's the question:
You can do setReadOnly() on a java.io.File object, but there's no analogous setReadWrite(). In fact, there seems to be no way to control the permissions or attributes of a File object.
So, has anybody figured out a workaround? How platform-specific is it? I'm trying to do something on OS/400, and so it will be a little different than anything else, although it will probably most closely resemble some sort of ISO Unix technique.
Joe
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it still can't be done in pure Java. If you are sure of the platform, you can use Runtime.exec(). But that's as platform specific as you can get.
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Runtime.exec() is probably still the only really good way to do this. What you might do is set up a .properties file contiaining the command/commands to set the permissions. Then, when you move to a different platform, you simply change the .properties file.
Not the most elegant solution, but it would mean that you don't have to re-compile code.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic