Re: How to set Permissions on New File

From: Anthony Borla (ajborla_at_bigpond.com)
Date: 10/28/03


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



Relevant Pages

  • Re: How to set Permissions on New File
    ... >> I've been reading up on file permissions (including FilePermission, ... > is nothing more than an interface to the relevant operating system ...
    (comp.lang.java)
  • Re: How to set Permissions on New File
    ... >> Permission, and Permissions). ... > nothing more than an interface to the relevant operating system ...
    (comp.lang.java)
  • Re: recovering NTFS volumes
    ... If ntfs permissions are not being copied when data is backed up then I believe it ... If the files did not include the administrators group ... but instead a user/group unique to the operating system that is was backed up from, ...
    (microsoft.public.win2000.security)
  • Re: File Permissions-Access Denial
    ... should not cause what happened but if you replace all permissions and permissions are ... One would be to boot from the install ... disk and install a parallel operating system on your computer [best into a separate ...
    (microsoft.public.win2000.security)
  • Re: adding more color display options??
    ... You will do better posting to a newsgroup for your operating system as ... Pick a Display newsgroup within the relevant operating system groups ... Alan Edwards, MS MVP W95/98 Systems ...
    (microsoft.public.windowsupdate)