Here you can find the source of getResourceAsReader(final Class> classLocation, final String resourceName)
Parameter | Description |
---|---|
classLocation | This class allows to find the package which is located the ressoure |
resourceName | The name of ressource |
Parameter | Description |
---|---|
IOException | In case of IO error |
public static Reader getResourceAsReader(final Class<?> classLocation, final String resourceName) throws IOException
//package com.java2s; /**//ww w.j ava2 s . c o m * * SIROCCO * Copyright (C) 2011 France Telecom * Contact: sirocco@ow2.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * * $Id$ * */ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; public class Main { /** * Get a ressource in classpath and convert it as Reader. * * @param classLocation This class allows to find the package which is * located the ressoure * @param resourceName The name of ressource * @return The Reader for the ressource * @throws IOException In case of IO error */ public static Reader getResourceAsReader(final Class<?> classLocation, final String resourceName) throws IOException { InputStream in = classLocation.getResourceAsStream(resourceName); if (null == in) { throw new IOException("Resource not found : " + resourceName); } return new InputStreamReader(in); } }