博客园 首页 私信博主 显示目录 隐藏目录 管理

java读取文本文件

很久没用都忘记了,记录一下:

public
static String readFileContent(String fileName) { File file = new File(fileName); BufferedReader reader = null; StringBuilder builder = new StringBuilder(); try { reader = new BufferedReader(new FileReader(file)); String tempStr; while ((tempStr = reader.readLine()) != null) { builder.append(tempStr); } reader.close(); return builder.toString(); } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e1) { e1.printStackTrace(); } } } return builder.toString(); }

 

posted @ 2020-09-08 13:01  MrSharp  阅读(175)  评论(0编辑  收藏  举报