Here you can find the source of getClassPathFile(String pathName)
public static File getClassPathFile(String pathName) throws Exception
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; import java.net.URL; public class Main { public static File getClassPathFile(String pathName) throws Exception { // In windows, pathnames with spaces are returned as %20 if (pathName.indexOf("%20") != -1) pathName = pathName.replaceAll("%20", " "); File tmp = new File(getResourceURL(pathName).getFile()); return tmp; }//from w w w . ja v a 2 s . co m public static URL getResourceURL(String resource) throws IOException { URL url = null; ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader != null) url = loader.getResource(resource); if (url == null) url = ClassLoader.getSystemResource(resource); if (url == null) throw new IOException("Resource " + resource + " was not found"); return url; } }