Originally posted by Fabio Saracino:
Hello Rob, I tried your suggestion and it works. But I have a problem, because the code, from which I find the path, is not the code of the application that I need the path. I have a class that walk through another class and I must find the path of the project of the second class in the first class!
Well it should work with any class, as long as the ClassLoader is playing nice
You just need to use that Class object's getResource method, and use that Class' class file. You could even tell where the
String class is located by calling String.class.getResource("String.class");
Originally posted by Brian Legg:
I'm just making stuff up but couldn't you create a File object (not an actual file) and it always makes your current directory the default. Then you could call some method to get the path from it (not sure what the method is called), then just append the current class name to the end?
Hope that helps at all.
Because the class can be found through the class path, and need not be relative to the current directory.