Here you can find the source of getRelativeResource(Class> clazz, String relativePath)
public static File getRelativeResource(Class<?> clazz, String relativePath)
//package com.java2s; //License from project: Apache License import java.io.File; import java.net.URL; public class Main { public static File getRelativeResource(Class<?> clazz, String relativePath) { String packageName = clazz.getPackage().getName(); String packagePath = packageName.replaceAll("\\.", "/"); String wholePath = packagePath + "/" + relativePath; URL url = Thread.currentThread().getContextClassLoader() .getResource(wholePath); if (url == null) { String message = String .format("File [%s] not found", wholePath); throw new IllegalArgumentException(message); }/*from ww w .j a v a2 s . c o m*/ return new File(url.getPath()); } }