Here you can find the source of readAllTextFromResource(String resourceName)
public static String readAllTextFromResource(String resourceName)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**//from w w w. j a v a 2 s .c om * Reads the entire resource text file. * * @param resourceName Name of the resource text file * * @return Content of the resource text file. */ public static String readAllTextFromResource(String resourceName) { String s = ""; ; InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName); try { ByteArrayOutputStream result = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length; while ((length = inputStream.read(buffer)) != -1) { result.write(buffer, 0, length); } s = result.toString("UTF-8"); } catch (Exception e) { // Omitted. } finally { try { inputStream.close(); } catch (IOException e) { // Omitted. } } return s; } }