Java中使用BufferedReader的readLine()方法读取文件内容


 

 

String filePath = "C:\\Users\\91911\\Desktop\\test.txt";//文件路径

File file = new File(filePath);

BufferedReader reader = null;

try {

  reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));//获取字符流

  String line;

  while((line = reader.readLine()) != null){

    System.out.println(line);//循环的到的数据

  }

}catch(Exception e){}

finally{

  if(reader != null){

    try{

      reader.close();

    }catch(Exception e1){

    }

  }

}

 

了解更多

https://blog.csdn.net/GuangRong1/article/details/88764539


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM