Here you can find the source of getSourceForResource(String s)
public static Object getSourceForResource(String s)
//package com.java2s; /**/* ww w. j av a 2 s . c om*/ * Copyright 2011 The ARIES Consortium (http://www.ariesonline.org) and * www.integratedmodelling.org. This file is part of Thinklab. Thinklab is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Thinklab 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 Thinklab. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.net.MalformedURLException; import java.net.URL; public class Main { /** * Analyze the passed string and determine if it specifies an existing file resource * or URL. Return the appropriate object, that must be disambiguated using instanceof. * Meant to (inelegantly) solve problems coming from file name encodings in primitive * OS (e.g. Windows) that cannot be handled properly in file:// URLs. * @return a valid URL, existing file, or null. No exceptions are thrown. */ public static Object getSourceForResource(String s) { File f = new File(s); if (f.exists()) return f; URL url = null; try { url = new URL(s); } catch (MalformedURLException e) { } if (url != null) return url; return null; } }