Java Resource Load getResource(Class c, String name)

Here you can find the source of getResource(Class c, String name)

Description

get Resource

License

Open Source License

Declaration

public static String getResource(Class c, String name) 

Method Source Code


//package com.java2s;
/*/*from w w w . j  a v  a2  s.  c o  m*/
 * Copyright (C) 2010-2011 VTT Technical Research Centre of Finland.
 *
 * 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;
 * version 2.1 of the License.
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

import java.io.InputStream;

import java.util.Scanner;

public class Main {
    public static String getResource(Class c, String name) {
        InputStream is = c.getResourceAsStream(name);
        StringBuilder text = new StringBuilder();
        Scanner scanner = new Scanner(is, "UTF-8");
        try {
            while (scanner.hasNextLine()) {
                text.append(scanner.nextLine());
                text.append("\n");
            }
        } finally {
            scanner.close();
        }
        return text.toString();
    }
}

Related

  1. getFilesRecurse(File dir, final String pattern)
  2. getFilesRecursevely(final String sourceFolder, final String classRegEx)
  3. getResource(Class c, String name)
  4. getResource(Class c, String path)
  5. getResource(Class clazz, String fileName)
  6. getResource(Class clazz, String name, String charset)