读取文本
程序员文章站
2022-07-05 14:48:45
...
- /**
- * 读取文本文件
- * @param filepath
- * @return
- */
- public static StringBuilder parser(String filepath) {
- InputStream inStream = StrUtils.class.getResourceAsStream(filepath);
- String encoding = "UTF-8";
- StringBuilder content = new StringBuilder();
- if(inStream != null){
- BufferedReader bufferedReader;
- try {
- InputStreamReader read = new InputStreamReader (inStream, encoding);
- bufferedReader = new BufferedReader(read);
- String c = bufferedReader.readLine();
- while(c != null){
- content.append(c);
- c = bufferedReader.readLine();
- }
- bufferedReader.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return content;
- }
上一篇: java gc
下一篇: 白名单屏蔽字 unicode字符范围