Java Resource Load getResourceAsString(String name)

Here you can find the source of getResourceAsString(String name)

Description

get Resource As String

License

Open Source License

Declaration

public static String getResourceAsString(String name) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.InputStream;
import java.util.Scanner;

public class Main {
    public static String getResourceAsString(String name) {
        InputStream is = getResource(name);
        Scanner scanner = new Scanner(is, "UTF-8");
        StringBuilder sb = new StringBuilder();
        while (scanner.hasNext()) {
            sb.append(scanner.nextLine()).append("\n");
        }//from ww  w  . j  a  v  a2  s  .c  o  m
        return sb.toString();
    }

    public static InputStream getResource(String name) {
        return Class.class.getResourceAsStream("/" + name);
    }
}

Related

  1. getResourceAsString(Class clazz, String resource)
  2. getResourceAsString(Class theClass, String fileName)
  3. getResourceAsString(final String resourceName, final Class caller, final String charset)
  4. getResourceAsString(InputStream in)
  5. getResourceAsString(InputStream resource)
  6. getResourceAsString(String path)
  7. getResourceAsString(String relativePath)
  8. getResourceAsTempFile(Object context, String resourceName)
  9. getResourceBundle(String baseName)