jQuery in Action, 2nd edition*
The moose likes Linux / UNIX and the fly likes Create Directory through Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Create Directory through Java " Watch "Create Directory through Java " New topic
Author

Create Directory through Java

John Lark
Ranch Hand

Joined: Feb 08, 2010
Posts: 72
Hey Guys,

So I am struggling through Linux issue and was hoping I might get some help. Currently I am trying to create a directory, which will be used to right files to. I don't actually create this directory till the first file is created. The code to create this directory is:

File dir = new file(/var/log/newFile);
dir.mkdirs();

The first is it keeps telling me I don't have permission to write the file, is there a way to override this?

The Second when I create the file manually I cant write to it... this should be taken care of with

dir.canWrite()... Correct?


Thanks,
Jonathan Larkin
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18713
    
    8

You don't have permission to create that directory? Then sure, there's a way to deal with that. But not through Java, of course. You just execute a suitable Unix command which grants you that permission, or you get somebody with enough permissions to run that command.
John Lark
Ranch Hand

Joined: Feb 08, 2010
Posts: 72
Okay I guess ill stuff it in the RPM spec file then, that seems to get run as root!

Thanks!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16160
    
  21

John Lark wrote:Okay I guess ill stuff it in the RPM spec file then, that seems to get run as root!

Thanks!


You can scratch the "seems to". RPMs installed as production OS components MUST be installed using root privileges - if for no other reason that the RPM database is not updatable by non-root users and until the database is updated, the package isn't officially "installed".


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Create Directory through Java