Here you can find the source of getPath(Class tClass)
public static String getPath(Class tClass)
//package com.java2s; //License from project: Open Source License import java.net.URL; public class Main { public static String getPath(Class tClass) { String rtn = null;//from w w w. j av a 2 s . c o m URL url = getURL(tClass); if (url != null) { rtn = url.getPath(); rtn = rtn.replace(tClass.getSimpleName() + ".class", ""); } return rtn; } public static URL getURL(Class tClass) { URL rtn = null; if (tClass != null) { ClassLoader cl = tClass.getClassLoader(); rtn = cl.getResource(tClass.getName().replace('.', '/') + ".class"); } return rtn; } }