Java Resource Load getResourceAsString(Class theClass, String fileName)

Here you can find the source of getResourceAsString(Class theClass, String fileName)

Description

get Resource As String

License

Apache License

Declaration

public static String getResourceAsString(Class<?> theClass, String fileName) throws IOException 

Method Source Code


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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class Main {
    public static String getResourceAsString(Class<?> theClass, String fileName) throws IOException {

        File f = new File(theClass.getResource(fileName).getFile());
        FileReader fr = new FileReader(f);
        BufferedReader br = new BufferedReader(fr);
        StringBuilder sb = new StringBuilder();
        String line = br.readLine();
        while (line != null) {
            sb.append(line + "\n");
            line = br.readLine();//from  ww w . ja  va2  s . c o m
        }
        return sb.toString();
    }
}

Related

  1. getResourceAsStream(String resourcePath)
  2. getResourceAsStreamInClassPath(@SuppressWarnings("rawtypes") Class clazz, String filepath)
  3. getResourceAsStrem(String name)
  4. getResourceAsString(Class clazz, String name)
  5. getResourceAsString(Class clazz, String resource)
  6. getResourceAsString(final String resourceName, final Class caller, final String charset)
  7. getResourceAsString(InputStream in)
  8. getResourceAsString(InputStream resource)
  9. getResourceAsString(String name)