Re: How to set Permissions on New File
From: Anthony Borla (ajborla_at_bigpond.com)
Date: 10/28/03
- Next message: FISH: "Re: ICMP packets"
- Previous message: Glen Herrmannsfeldt: "Re: char to string ????"
- In reply to: Hal Vaughan: "How to set Permissions on New File"
- Next in thread: Hal Vaughan: "Re: How to set Permissions on New File"
- Reply: Hal Vaughan: "Re: How to set Permissions on New File"
- Reply: Phil...: "Re: How to set Permissions on New File"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 28 Oct 2003 08:24:44 GMT
Hal,
"Hal Vaughan" <hal@thresholddigital.com> wrote in message
news:GTmnb.46726$HS4.219485@attbi_s01...
>
> I've been reading up on file permissions (including FilePermission,
> Permission, and Permissions). From what I see, these are
> temporary and forgotten when a program exits (if I'm wrong, tell
> me, please).
>
They represent the access the current process and its children [i.e. your
running program] has to the specified files. In other words, they make sense
only in context of the current program, and, yes, do not actually alter any
system-level, file-specific attributes.
>
> I'm installing a program on a computer and that includes
> configuration files that change regularly. When I create the
> configuration files, I want them to be readable and writable by
> any user running the program, otherwise my
> program won't be able to function.
>
This is easily achieved using the relevant operating system utility which is
nothing more than an interface to the relevant operating system function(s)
/ call(s) which actually perform such tasks. A system administrator would
normally call such utilities from a script file, or perhaps use a friendly
graphical interface to execute them.
For instance, on Windows-family systems the 'attrib' and 'cacls' utilities
would likely be used, while on *NIX and Linux systems the relevant utilities
are 'chmod' and 'chown'. In both cases, however, 'friendlier' utilities may
well exist.
>
> So how can I, from Java, find a way to set the permissions
> on a file I create (from within Java) so all users can read and
> write that file whenever they run the program?
>
The simplest approach is to launch the relevant operating system utilities
from within your application via 'Runtime.exec'. Dig out the applicable
operating system manuals and start experimenting :)
A much cleaner approach is to use JNI routines which tap into the relevant
operating system functionality. A web search may help discover a suitable
library if this approach is preferred.
>
> My first thought was to have the program itself, whenever it
> was started, set the permissions with a FilePermission object,
> but that doesn't make sense -- if files are not readable or writable
> by a user, it wouldn't make sense to allow that user to change the
> permissions.
>
Correct.
>
> Thanks for any info.
>
I hope this helps.
Anthony Borla
- Next message: FISH: "Re: ICMP packets"
- Previous message: Glen Herrmannsfeldt: "Re: char to string ????"
- In reply to: Hal Vaughan: "How to set Permissions on New File"
- Next in thread: Hal Vaughan: "Re: How to set Permissions on New File"
- Reply: Hal Vaughan: "Re: How to set Permissions on New File"
- Reply: Phil...: "Re: How to set Permissions on New File"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|