从.txt文件中读取和显示数据 [英] Reading and displaying data from a .txt file

查看:422
本文介绍了从.txt文件中读取和显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从.txt文件中读取和显示数据?

How do you read and display data from .txt files?

推荐答案

BufferedReader in = new BufferedReader(new FileReader("<Filename>"));

然后,你可以使用in.readLine();一次读一行。要读到最后,请写一个while循环:

Then, you can use in.readLine(); to read a single line at a time. To read until the end, write a while loop as such:

String line;
while((line = in.readLine()) != null)
{
    System.out.println(line);
}
in.close();

这篇关于从.txt文件中读取和显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆