• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

specify relative path in File constructor

 
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.
 
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.
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic