Here you can find the source of readFileFromClassPath(String file)
Parameter | Description |
---|---|
file | a parameter |
public static String readFileFromClassPath(String file)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**// w w w . j a va 2s .c o m * Read file from class path * * @param file * @return */ public static String readFileFromClassPath(String file) { InputStream is = ClassLoader.getSystemResourceAsStream(file); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String content = ""; String line; try { while ((line = br.readLine()) != null) content = content + line + "\n"; } catch (IOException e) { throw new RuntimeException("Unable to read file from templates"); } finally { try { is.close(); br.close(); } catch (IOException e) { // Ignore } } return content; } }