*
The moose likes Linux / UNIX and the fly likes expand the ./filename to fully qualified path automatically 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 "expand the ./filename to fully qualified path automatically" Watch "expand the ./filename to fully qualified path automatically" New topic
Author

expand the ./filename to fully qualified path automatically

shield kumar
Greenhorn

Joined: Feb 05, 2009
Posts: 28
I have a java file which takes a filename as parameter with fully qualified path(starting from root '/').
I use this java file in UNIX m/c.

This is how I execute my java file


I want here that user should be able to give just the filename as parameter not with fully qualified path.
I want that somehow the xyz class comes to know where the param.txt is located without the user specifying it's full path.
Sumit Bisht
Ranch Hand

Joined: Jul 02, 2008
Posts: 329

try this:

Remember, it is always recommended to use relative paths.
If you still want to use absolute paths, then you can create an environment variable and use relative filename.
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Punit, Sumit,

f.getAbsolutePath() will search file only in the current directory (.). If you want to extend the search , possibly in all classpaths use ClassLoader getResource().

shield kumar
Greenhorn

Joined: Feb 05, 2009
Posts: 28
thank you all guys
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951
    
  19

Actually, getAbsolutePath doesn't search, anywhere. It was confusing to me when I first learned Java, but a java.io.File doesn't actually represent a file, it represents a reference to a file. So you can define File objects for files and directories that don't physically exist.

If you do this:


a File object will be constructed. Since no parent directory was supplied, the current working directory will be assumed for a relative pathname supplied on the Java command line. Absolute pathnames are absolute, so if you type an absolute filename path on the command line, the path in the File object will be the file and its absolute path.

Here's a common usage:



Alternatively, you could open a FileInputStream on the File and catch FileNotFoundException.


Customer surveys are for companies who didn't pay proper attention to begin with.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

shield kumar wrote:I want here that user should be able to give just the filename as parameter not with fully qualified path.
I want that somehow the xyz class comes to know where the param.txt is located without the user specifying it's full path.

Filenames are only unique together with the path. How shall your program handle a file /xyz/param.txt and another one /abc/param.txt?


http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: expand the ./filename to fully qualified path automatically
 
Similar Threads
How to make FormFile return fully qualified file name?
Tomcat 4.0 issue
expand the ./filename to fully qualified path automatically
K&B: Has-a relationship
How to create File object for servlet and so where to place the folder