软件编程
位置:首页>> 软件编程>> java编程>> java 按行读取文件并输出到控制台的方法

java 按行读取文件并输出到控制台的方法

作者:空空dream  发布时间:2022-10-28 22:48:20 

标签:java,文件,控制台

如下所示:


public static void main(String[] args) throws IOException {
   /*
    * 1.打开一个file
    * 2.new一个InputStreamReader←FileInputStream←file
    * 3.用BufferedReader(←InputStreamReader)的readLine()方法读取
    * */
   File ctoFile = new File("C://Users//gl//Desktop//ku//51cto.txt");
   InputStreamReader rdCto = new InputStreamReader(new FileInputStream(ctoFile));
   BufferedReader bfReader = new BufferedReader(rdCto);
   String txtline = null;
   while ((txtline = bfReader.readLine()) != null) {
     System.out.println(txtline);
   }
   bfReader.close();
 };

来源:https://blog.csdn.net/lglglgl/article/details/51654863

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com