public static String file2String(Class clazz, String relativePath, String encoding) throws IOException {
        InputStream is = null;
        InputStreamReader reader = null;
        BufferedReader bufferedReader = null;
        try {
            is = clazz.getResourceAsStream(relativePath);
            reader = new InputStreamReader(is, encoding);
            bufferedReader = new BufferedReader(reader);
            StringBuilder context = new StringBuilder();
            String lineText;
            while ((lineText = bufferedReader.readLine()) != null) {
                context.append(lineText).append(LINE_SEPARATOR);
            }
            return context.toString();
        } finally {
            if (bufferedReader != null) {
                bufferedReader.close();
            }
            if (reader != null) {
                reader.close();
            }
            if (is != null) {
                is.close();
            }
        }
    }
public static String file2String ( Class clazz , String relativePath , String encoding ) throws IOException { InputStream is = null ; InputStreamReader reader = null ; BufferedReader bufferedReader = null ; try { is = clazz . getResourceAsStream ( relativePath ) ; reader = new InputStreamReader ( is , encoding ) ; bufferedReader = new BufferedReader ( reader ) ; StringBuilder context = new StringBuilder ( ) ; String lineText ; while ( ( lineText = bufferedReader . readLine ( ) ) != null ) { context . append ( lineText ) . append ( LINE_SEPARATOR ) ; } return context . toString ( ) ; } finally { if ( bufferedReader != null ) { bufferedReader . close ( ) ; } if ( reader != null ) { reader . close ( ) ; } if ( is != null ) { is . close ( ) ; } } }
读取类相对路径内容

@param clazz        文件
@param relativePath 相对路径
@param encoding     编码
@return 文件内容
@throws IOException 发送IO异常