In this section of example we are going to describe you how to fetch the class directory's path by the class name. To get the class directory's name and its path we have used two methods getClass() and getResource() over an object instance.
We have created a class GetClassDirectory and to get the class of an object we have created a new instance of Object class and then we have called the getClass() method and to get the path of that class directory we have used getResource() method.
URL url=new Object().getClass().getResource("Object.class");
new Object().getClass().getResource("Object.class") returns an object of type java.net.URL.Here is the example code of GetClassDirectory.java as follows:
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: October 23, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles