Here you can find the source of getResource(String filename)
public static URL getResource(String filename)
//package com.java2s; /*/* w w w . j a va 2 s . co m*/ * StatCvs-XML - XML output for StatCvs. * * Copyright by Steffen Pingel, Tammo van Lessen. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.io.File; import java.net.MalformedURLException; import java.net.URL; public class Main { /** * Returns a url to a resource. The classpath is searched first, * then the file system is searched. */ public static URL getResource(String filename) { URL url = ClassLoader.getSystemResource(filename); if (url == null) { url = Main.class.getResource(filename); if (url == null) { try { url = new File(filename).toURL(); } catch (MalformedURLException e) { return null; } } } return url; } }