aspose file tools*
The moose likes Beginning Java and the fly likes specify relative path in File constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "specify relative path in File constructor" Watch "specify relative path in File constructor" New topic
Author

specify relative path in File constructor

Jay Ram
Ranch Hand

Joined: Dec 13, 2005
Posts: 40
Hi,
I am trying to construct a File object. I want to specify a relative path for the file name.
If I specify the absolute path, it works file
like
File F = new File("C:\\myFile","myFile.xml");

But if I want to access the file in the same folder and say
File F = new File("myFile.xml");

It says file not found.

How do I specify the file path without specifying the full path so that the code will be system independent.

Pls advise.

Regards,
Jay.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3528
    
  15
Try printing the value of to make sure your working directory is actually the location of the myFile.xml file.


Joanne
Jay Ram
Ranch Hand

Joined: Dec 13, 2005
Posts: 40
Thx for the response Joanne.

I tried that and as u had suggested, the current working directory is different. I am working with weblogic workshop and apparently the classes are stored in a different directory. How do I specify the directory now?
Where do I put the file? I am tryimg to parse an XML file frfom inside my class.

Please advise.

Regards,
jaya.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3528
    
  15
If you want to be completely system independent you will need to tell your program where the file is, either using a command line argument to your program, a -D option to java or storing it in a configuration file or database that gets created by your install program.
[ June 22, 2006: Message edited by: Joanne Neal ]
Jay Ram
Ranch Hand

Joined: Dec 13, 2005
Posts: 40
Thanks Joanne. Will try it by storing it in a properties file.

Thanks again,
Jay.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: specify relative path in File constructor