Here you can find the source of findClassOriginFile(Class cls)
public static File findClassOriginFile(Class cls)
//package com.java2s; import java.io.File; import java.net.URL; public class Main { public static File findClassOriginFile(Class cls) { // Try to find the class file. try {//from www .ja v a2 s .co m final URL url = cls.getClassLoader().getResource(cls.getName().replace('.', '/') + ".class"); final File file = new File(url.getFile()); // toString() if (file.exists()) return file; } catch (Exception ex) { } // Method 2 try { URL url = cls.getProtectionDomain().getCodeSource().getLocation(); final File file = new File(url.getFile()); // toString() if (file.exists()) return file; } catch (Exception ex) { } return null; } }