Here you can find the source of getClassFilePath(Class> clazz)
public static String getClassFilePath(Class<?> clazz)
//package com.java2s; import java.io.File; import java.io.UnsupportedEncodingException; public class Main { public static String getClassFilePath(Class<?> clazz) { java.net.URL url = clazz.getProtectionDomain().getCodeSource().getLocation(); String filePath = null;/*from ww w . j a v a 2 s . c om*/ try { filePath = java.net.URLDecoder.decode(url.getPath(), "utf-8"); } catch (UnsupportedEncodingException ignore) { } File file = new File(filePath); return file.getAbsolutePath(); } }