I create a new folder Fold inside my eclipse project Proj. How do I get the path of Fold relative to Proj ? This folder will be used as place to store serialized objects. Will I be able to serialize and de-serialize my code using this relative path ?
Asked
Active
Viewed 3,288 times
0
-
right click on your folder to get its absolute path and its path from the project folder. `System.getResouce("user.dir");` gives the path of the project. – Justin Apr 03 '13 at 15:26
2 Answers
0
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL url = classLoader.getResource("path/folder");
or
URL url = getClass().getResource("path/folder");

Biswajit
- 2,434
- 2
- 28
- 35
-
I don't know these things, but I was expecting that the answer will contain some info about the Project Folder, User Folder etc. Looks like your answer will be valid only when you know the absolute path. I know the absolute. I need to know how to get a relative path ans make your java code able to find the folder specified by that path. – david blaine Apr 03 '13 at 15:20
-
1check the link http://stackoverflow.com/questions/11073702/java-file-relative-path-in-eclipse – Biswajit Apr 03 '13 at 15:23
0
This code gets the path -
String absolutePath = new File(".").getAbsolutePath();
System.out.println(absolutePath);// Shows you the path of your Project Folder
int last = absolutePath.length()-1;
absolutePath = absolutePath.substring(0, last);//Remove the dot at the end of path
System.out.println(absolutePath);
String filePath = "MyFolderInsideEclipseProject\\file.txt";//You know this
System.out.println(absolutePath + filePath);//Get the full path.

david blaine
- 5,683
- 12
- 46
- 55