Here you can find the source of readFileFromResource(String filename)
Parameter | Description |
---|---|
filename | xx.text |
public static String readFileFromResource(String filename)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; public class Main { /**/*ww w. j a v a 2 s . c o m*/ * * @param filename xx.text * @return */ public static String readFileFromResource(String filename) { try { InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename); BufferedReader br = new BufferedReader(new InputStreamReader(is)); StringBuilder stringBuilder = new StringBuilder(); String line; while ((line = br.readLine()) != null) { stringBuilder.append(line); } br.close(); return stringBuilder.toString(); } catch (Exception e) { e.printStackTrace(); } return null; } }