473,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to set Permissions on New File

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).

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.

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?

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.

Thanks for any info.

Hal
Jul 17 '05 #1
6 24153
Hal,

"Hal Vaughan" <ha*@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
Jul 17 '05 #2
Thanks! It helps a lot.

I was looking at using native commands, since I couldn't find anything else.
For me, that is a last resort, since it means writing a special
implementation for each OS the installer works on, and I was hoping to keep
it as multi-platform as possible (part of the reason I'm using Java). At
least using chmod will work for most OSs out there and I have a book on
Windows scripting to take care of that.

You also provide a lot of useful and clear information. Your comments are a
big help and greatly appreciated.

Hal

Anthony Borla wrote:
Hal,

"Hal Vaughan" <ha*@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


Jul 17 '05 #3
I thought JNI would not give the programm
more permissions than that of the user that
ran the program -- else anyone could rm -rf *
"Anthony Borla" <aj*****@bigpond.com> wrote in message
news:gJ*********************@news-server.bigpond.net.au...
Hal,

"Hal Vaughan" <ha*@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

Jul 17 '05 #4
Phil,

"Phil..." <ry***@ieee.org> wrote in message
news:rAxnb.51456$HS4.234306@attbi_s01...
I thought JNI would not give the programm
more permissions than that of the user that
ran the program -- else anyone could rm -rf *


JNI simply allows you to tap into functionality not offered in Java. When
using JNI you bypass the JVM, and surrender control of you application to
'foreign' code, code which can pretty well do anything it wants *within
operating system constraints* !

The JVM and application execute within the context of a user account [or
similar], and are bound by the security and other restrictions imposed on
that account. So, to use your example, a JNI routine may possibly allow you
to perform the equivalent of a 'rm -rf', but unless the user account [or
similar] has the requisite permission(s), the attempt will fail with the
operating system 'trapping' the attempt, and somehow handling / logging it.
A JNI routine will, to be considered robust, handle such possibilities
predictably and gracefully allowing the application to handle the situation
as required.

It may help to think of an [Java] application's [not applet] execution
environment as a layered entity, somewhat like an onion. The application
executes under the supervision and control of the JVM but may, using
facilities like JNI, temporarily bypass that layer when necessary. When
doing so it will encounter the operating system layer, typically the
security a sub-system. In either case the application is bound by the
constraints imposed by that layer, constraints which would normally have
been imposed *before* application execution, and [probably] cannot be
altered without a restart.

I hope this helps.

Anthony Borla
Jul 17 '05 #5
Hal,

"Hal Vaughan" <ha*@thresholddigital.com> wrote in message
news:FLvnb.38539$ao4.82577@attbi_s51...
Thanks! It helps a lot.

A pleasure :) !

I was looking at using native commands, since I couldn't
find anything else. For me, that is a last resort, since it means
writing a special implementation for each OS the installer works
on, and I was hoping to keep it as multi-platform as possible
(part of the reason I'm using Java). At least using chmod will
work for most OSs out there and I have a book on
Windows scripting to take care of that.

Application installation [as opposed to applet installation] is inherently
operating-system specific [just look at all those .tar and .zip files out
there in cyberspace !]. It certainly pays to be familiar with all the
installation-related utilities, and scripting facilities offered by the
target platforms.

You also provide a lot of useful and clear information.Your
comments are a big help and greatly appreciated.


My belief is to try [where possible, and, of course, relavant] to explain
general principles in forum responses. After all, answers to very-specific
questions can easily be obtained from text books and manuals [not to mention
Google searches :) !].

Cheers,

Anthony Borla
Jul 17 '05 #6
Anthony Borla wrote:
Hal,

"Hal Vaughan" <ha*@thresholddigital.com> wrote in message
news:FLvnb.38539$ao4.82577@attbi_s51... <snip>

You also provide a lot of useful and clear information.Your
comments are a big help and greatly appreciated.


My belief is to try [where possible, and, of course, relavant] to explain
general principles in forum responses. After all, answers to very-specific
questions can easily be obtained from text books and manuals [not to
mention Google searches :) !].


It is much appreciated. Although I had tried several Google searches and
some other research, I didn't find anything that specifically told me I
could not do what I wanted in Java, so getting a full answer was definately
helpful. Your extra effort is a big help (and I'm sure, one day, it'll
help someone else who finds this thread in a Google search).

Hal
Cheers,

Anthony Borla


Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tracy Tripp | last post by:
I'm working on a program that takes files by path and moves them into new locations, and then back again if the user intends. Everything is great so far except I cannot figure out how to keep...
0
by: Fran Tirimo | last post by:
I am developing a small website using ASP scripts to format data retrieved from an Access database. It will run on a Windows 2003 server supporting FrontPage extensions 2002 hosted by the company...
2
by: Fran Tirimo | last post by:
I am developing a small website using ASP scripts to format data retrieved from an Access database. It will run on a Windows 2003 server supporting FrontPage extensions 2002 hosted by the company...
1
by: Maurice Mertens | last post by:
Hi all, is it possible to programmatically determine the current users permissions on a file / directory? I want to check if the user can add/delete files to a folder. -- Met vriendelijke...
6
by: !!! Klutzo !!! | last post by:
I give permissions for ASPNET on a top level subdirectory. A windows program copies a file into the subdirectory, however, my web service cannot access the file because it does not have...
3
by: rick baker | last post by:
I have two projects in a solution and have recently upgraded to Net Framework 1.1. It's not clear if the problem is directly related to the upgrade or not. One of my directories returns an error...
15
by: David Thielen | last post by:
Hi; My ASP.NET app (C# calling J# under .net 2.0) creates a png file in a subdirectory to display as part of the created page. However, the bitmap will not display due to a security violation. ...
7
by: none | last post by:
Hello: I had a nice php application running on my server here at home, and I uploaded it to a shared public type server and it started to break all over the place. It turns out that some...
1
by: beary | last post by:
Hello everyone, I'm not sure if this is the correct forum for this, and apologies for the length of this question, but I'm desperate for some good advice... I'm in way over my head with file...
2
by: beary | last post by:
Hello everyone, I posted this in unix/linux but it received no replies, so I assume it was the wrong forum. I'm trying here. I'm in way over my head with file permissions. The directory and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.