Here you can find the source of getProgramRootPath(Class clazz)
public static String getProgramRootPath(Class clazz)
//package com.java2s; import java.io.File; import java.net.URL; public class Main { public static String getProgramRootPath(Class clazz) { try {/*from w ww . ja va 2 s . c om*/ return java.net.URLDecoder .decode(getClassPathFile(clazz).getParentFile().getParentFile().getAbsolutePath(), "UTF-8"); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); return ""; } } public static File getClassPathFile(Class clazz) { File file = getClassFile(clazz); for (int i = 0, count = clazz.getName().split("[.]").length; i < count; i++) file = file.getParentFile(); if (file.getName().toUpperCase().endsWith(".JAR!")) { file = file.getParentFile(); } return file; } public static File getClassFile(Class clazz) { URL path = clazz.getResource(clazz.getName().substring(clazz.getName().lastIndexOf(".") + 1) + ".classs"); if (path == null) { String name = clazz.getName().replaceAll("[.]", "/"); path = clazz.getResource("/" + name + ".class"); } return new File(path.getFile()); } }