File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes File Permissions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "File Permissions" Watch "File Permissions" New topic
Author

File Permissions

Joe Pluta
Ranch Hand

Joined: Jun 23, 2003
Posts: 1376
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

Joined: May 26, 2003
Posts: 30752
    
156

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821

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.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File Permissions