aspose file tools
The moose likes Beginning Java and the fly likes How to make it relative path? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "How to make it relative path?" Watch "How to make it relative path?" New topic
Author

How to make it relative path?

Max Bean
Ranch Hand

Joined: Mar 09, 2006
Posts: 31
Suppose I create my FileInputStream like this:

in = new FileInputStream("c:/projects/study/college/test/parameters.xml");

, is there any way else to access parameters.xml without using the hardcoded-path that way?
Roger F. Gay
Ranch Hand

Joined: Feb 16, 2007
Posts: 334
If the path is relative to your application, then:

getPath()
getAbsolutePath()
getCanonicalPath()

If you want a configurable path, place a configuration file where your application knows where to find it (relatively speaking) and read the path from the configuration file.


Correlation does not prove causality.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1318

here is an example Code:



is this what you looking for..


Saifuddin..
[Linkedin] How To Ask Questions On JavaRanch My OpenSource
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Relative to what might be the question. This line:

will create a file relative to the current user directory. See System Properties to get the current home.

You can also make a file relative to another file or a path string:


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make it relative path?
 
Similar Threads
need help!!! please
retrieve a file from a fileinputstream
Is indexof only way of identify in file type
reading a file without mentioning the whole path
NX:window XP - java.io.FileNotFoundException