Here you can find the source of getDirectoryPath(Class
public static <T> String getDirectoryPath(Class<T> owner)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.net.URL; public class Main { /**//from w ww. j ava 2 s . c o m * Get directory path according to Class. */ public static <T> String getDirectoryPath(Class<T> owner) { String packageName = owner.getPackage().getName().replace(".", String.valueOf(File.separator)); URL resource = owner.getClassLoader().getResource(packageName); if (resource != null) { return resource.getPath(); } return null; } }