Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

specify relative path in File constructor

 
Jay Ram
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try printing the value of to make sure your working directory is actually the location of the myFile.xml file.
 
Jay Ram
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joanne. Will try it by storing it in a properties file.

Thanks again,
Jay.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic