File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Creating a file by giving relative path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating a file by giving relative path" Watch "Creating a file by giving relative path" New topic
Author

Creating a file by giving relative path

Krishna Unni
Greenhorn

Joined: Jun 01, 2006
Posts: 5
How can i create a file by giving 'relative path' as parameter like '../Logging/note.log' ?.
Fahd Shariff
Ranch Hand

Joined: Nov 22, 2002
Posts: 38
File file = new File("../Logging/note.log") ;


Fahd Shariff<br />"Let the code do the talking"
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

"Krishna T K,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name. First names can be initials, but last names cannot.

You can edit your display name here.

Thank you for your prompt attention, and enjoy the ranch!

-Marc


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

The problems I see with using relative paths are -
1) You can't be sure where the files are being created since it depends on how the application is invoked.
2) You may not have permission to write to the directory.

I try to create files in directories that I know I have permission. For example System.getProperty("user.home") is, as the name suggests, the user 'home' directory and one should be able to assume that a process running as a particular user can create files (or directories) in that user's home directory. If one is in any doubt then one can always use File.canWrite() .

If you just want a temporary file then one of the File.createTempFile(...) methods can be used or you can look use the system temporary directory which can be obtained from System.getProperty("java.io.tmpdir").


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Krishna --

Please try again with the name. You need two names, first and last. No initials for the last name. Thanks.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a file by giving relative path
 
Similar Threads
Finding if files exist.. file on local machine, problems on server
suncertify.properties
Facing issue in Internet Explorer, but same works fine in Mozilla Firefox
JSP and Path related Question
problem with RequestDispatcher