jason
jason

Reputation: 189

Java eclipse referencing files in project using relative paths

I am trying to upload something to the web using one of Apache's client libraries. However I am having trouble locating the resource file to upload. My project setup looks like this:

Root/src/a/b/c/d/program.java

Root/resource/resourceFile.txt

I was wondering what the string path would be for referencing that resource file from program.java?

File f = new File("what path would go here?");

Thanks in advance.

Upvotes: 1

Views: 4048

Answers (1)

Hajo Thelen
Hajo Thelen

Reputation: 1135

  • Eclipse will (by default) not include this file in the built project.
  • The Project Path Information from Eclipse environment is not available in the built project

If you run this in Eclipse, it will display the base path of your application.

Find out with

File f = new File(".");
System.out.println(f.getAbsolutePath());

Tips :

  1. Read Documentation of Java API
  2. For questions like this write minmal test programs

Upvotes: 1

Related Questions