美文网首页
Java读取TXT文件

Java读取TXT文件

作者: 空格键_尘 | 来源:发表于2019-02-28 11:51 被阅读0次
StringBuilder txtValue = new StringBuilder();
public static void readTxtFile(String filePath){
        try {
                InputStreamReader read = new InputStreamReader(new FileInputStream(fileContent.getFname()), "UTF-8");// 考虑到编码格式
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt ;
                while ((lineTxt = bufferedReader.readLine()) != null) {
                    log.info("readTxt:" + lineTxt);
                    lineTxt += " <br>";
                    txtValue.append(lineTxt);
                }
                read.close();
            }catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
}

相关文章

网友评论

      本文标题:Java读取TXT文件

      本文链接:https://www.haomeiwen.com/subject/purhuqtx.html