源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

java读取txt文件代码片段

  • 时间:2022-05-01 05:05 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:java读取txt文件代码片段
本文实例为大家分享了java读取txt文件的具体代码,供大家参考,具体内容如下 [b]学习小记:[/b]   1、首先要根据路径获取你的 txt 文本文件。File file = new File(path);   2、将获取到的这个字节码流读进缓存。new FileInputStream(file) ;   3、然后对刚才读进缓存的输入流进行解读,生成对应字节流。InputStreamReader(readIn)   4、再然后通过 BufferedReader 这个类进行一行一行的输出。bufferedReader.readLine() 代码:
public static void ReadTxt () {
 try { 
  File file = new File("E:\\text.txt");
  FileInputStream readIn = new FileInputStream(file);
  InputStreamReader read = new InputStreamReader(readIn, "utf-8");
  BufferedReader bufferedReader = new BufferedReader(read);
  String oneLine= null;
  while((oneLine= bufferedReader.readLine()) != null){
    System.out.println(lineTxt);
  }
  read.close();
 } catch (Exception e) {
  System.out.println("读取文件内容出错");
  e.printStackTrace();
 }
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部