Java Resource Load getResourceAsString(String path)

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

Description

get Resource As String

License

Apache License

Declaration

public static String getResourceAsString(String path) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;

import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static String getResourceAsString(String path) throws Exception {

        InputStream is = ClassLoader.getSystemResourceAsStream(path);
        BufferedReader br = null;
        StringBuilder sb = new StringBuilder();

        String line;/*from   w  w w. jav  a2  s  .co  m*/
        try {

            br = new BufferedReader(new InputStreamReader(is));
            while ((line = br.readLine()) != null) {
                sb.append(line).append('\n');
            }

        } finally {
            if (br != null) {
                br.close();
            }
            is.close();
        }

        return sb.toString();

    }
}

Related

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