This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 18541
    
    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: 15950
    
  19

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
 
Similar Threads
Scanning/Storing a String that the user enters?
Decompress a zip file in java
In webApps how to create a new image and present it through a html ?
can log4j create a directory for logging ?
Tomcat cannot unzip a War file