Java Resource Load getResourceAsString(String relativePath)

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

Description

get Resource As String

License

Open Source License

Declaration

public static String getResourceAsString(String relativePath) 

Method Source Code

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

import java.io.IOException;
import java.io.InputStream;

import java.util.Scanner;

public class Main {
    public static String getResourceAsString(String relativePath) {
        InputStream inputStream = Thread.currentThread()
                .getContextClassLoader().getResourceAsStream(relativePath);
        Scanner s = new Scanner(inputStream, "UTF-8");
        Scanner s2 = s.useDelimiter("\\A");
        String result = s2.hasNext() ? s2.next() : "";
        s.close();/*w  w  w .jav a  2  s  .  com*/
        s2.close();
        try {
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }
}

Related

  1. getResourceAsString(final String resourceName, final Class caller, final String charset)
  2. getResourceAsString(InputStream in)
  3. getResourceAsString(InputStream resource)
  4. getResourceAsString(String name)
  5. getResourceAsString(String path)
  6. getResourceAsTempFile(Object context, String resourceName)
  7. getResourceBundle(String baseName)
  8. getResourceBundle(String resourceURI, Locale targetLocale)
  9. getResourceBundleForLoc(String language, String fileName)