获取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); } } }
标签:文件,lineTxt,获取,file,new,xpStr,cr,txt,String 来源: https://www.cnblogs.com/zwh0910/p/15761668.html