• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to define relative path in side java program for the following project structure?  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is the package structure in eclipse ide:
|--EclipseProject
| |--src
| | |--beans
| | |+Client.java
| |--applicationContext.xml

I am try to using the following two statements to access applicationContext.xml file inside the Client.java but it is printing FileNotFound.Please give me the solution how to define relative path of file.Please Generalize it to any file.


File file=new File("applicationContext.xml");
File file=new File("./applicationContext.xml");
File file=new File("../applicationContext.xml");

if(!file.exists()){
System.out.println("File Not Found");
}

It is working for only absolute path only that is for following path:
File file=new File("E:/MyWork/workspace/TestSpringPrjEnv/src/applicationContext.xml");

 
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on where you're running it from--in other words, the "current" directory.

You'd be better off loading it as a classpath resource.
 
Kumar Maddu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Newton wrote:It depends on where you're running it from--in other words, the "current" directory.

You'd be better off loading it as a classpath resource.



Hi David,

Please give me example how to load it as a classpath
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!