Win a copy of Terraform in Action this week in the Cloud forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

specify relative path in File constructor

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Joanne. Will try it by storing it in a properties file.

Thanks again,
Jay.
 
reply
    Bookmark Topic Watch Topic
  • New Topic