This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kumar Maddu
Greenhorn
Posts: 6
  • 0
  • 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");

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • 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
  • 0
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic