Android Path to URL Convert getResource(String strName)

Here you can find the source of getResource(String strName)

Description

Return resource from local file, if false then search from classpath

Parameter

Parameter Description
strName String

Exception

Parameter Description
Exception an exception

Return

InputStream

Declaration

// //////////////////////////////////////////////////////
public static java.net.URL getResource(String strName) 

Method Source Code

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main{
    /**/* w  w w. j av a 2  s  .  co  m*/
     * Return resource from local file, if false then search from classpath
     * 
     * @param strName
     *            String
     * @return InputStream
     * @throws Exception
     */
    // //////////////////////////////////////////////////////
    public static java.net.URL getResource(String strName) {
        try {
            File fl = new File(strName);
            if (fl.exists() && fl.isFile())
                return fl.toURI().toURL();
        } catch (Exception e) {
        }
        if (!strName.startsWith("/"))
            return FileUtil.class.getResource("/" + strName);
        else
            return FileUtil.class.getResource(strName);
    }
}