wood burning stoves 2.0
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "File Permissions" Watch "File Permissions" New topic

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.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32636

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

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
It's not a secret anymore!