获取txt文件的内容

代码如下:

public class TxtAnalysisTest {
    public static void main(String[] args) throws IOException {
        String lineTxt_cr = null;//行读字符串
        String encoding="GBK";
        File file = new File("C:\\Users\\miracle\\Desktop\\a.txt");
        if(file.isFile() && file.exists()) { //判断文件是否存在
            InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);//考虑到编码格式
            BufferedReader bufferedReader = new BufferedReader(read); // 字符缓冲输入流
            StringBuffer xpStr = new StringBuffer(); //文件文本字符串
            while((lineTxt_cr = bufferedReader.readLine()) != null){
            //处理字符串lineTxt_cr
                xpStr.append(lineTxt_cr);
            }
            // 释放资源
            bufferedReader.close();
       read.close(); System.out.println(xpStr); } } }

 

上一篇:论文笔记 ACL 2018|Zero-Shot Transfer Learning for Event Extraction


下一篇:Linux基本权限类别