逐行读取文件 [英] Read from file line by line

查看:60
本文介绍了逐行读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个初学者。


我需要逐行读取TXT文件


怎么做?

I am a beginer.

I need to read a TXT file line by line

How to do it?

推荐答案

9月28日上午5:23,denislag ... @ gmail.com写道:
On Sep 28, 5:23 am, denislag...@gmail.com wrote:

我是一个初学者。


我需要逐行读取TXT文件


怎么做?
I am a beginer.

I need to read a TXT file line by line

How to do it?



查找StreamReader及其ReadLine方法。


谢谢,


Seth Rowe

Look up the StreamReader and it''s ReadLine method.

Thanks,

Seth Rowe


9月28日上午5:23,denislag ... @ gmail.com写道:
On Sep 28, 5:23 am, denislag...@gmail.com wrote:

我是初学者。


我需要逐行读取TXT文件


如何去做吧?
I am a beginer.

I need to read a TXT file line by line

How to do it?



尝试这样的事情:


static void Main()

{

FileStream fileStream = null;

StreamReader streamReader = null;

试试

{

fileStream = new FileStream(@" c:\foo.txt",FileMode.Open);

streamReader = new StreamReader(fileStream);

while(true )

{

string line = streamReader.ReadLine();

if(string.IsNullOrEmpty(line))

休息;

}

}

终于

{

if( streamReader!= null)

streamReader.Close();

if(fileStream!= null)

fileStream.Close();

}

}


希望它有所帮助,

John

Hi, try something like this:

static void Main()
{
FileStream fileStream = null;
StreamReader streamReader = null;
try
{
fileStream = new FileStream(@"c:\foo.txt", FileMode.Open);
streamReader = new StreamReader(fileStream);
while (true)
{
string line = streamReader.ReadLine();
if (string.IsNullOrEmpty(line))
break;
}
}
finally
{
if (streamReader != null)
streamReader.Close();
if (fileStream != null)
fileStream.Close();
}
}

Hope it helps,
John


StreamReader reader = new StreamReader(filePath); // filepatj =" C:/aa.txt"

while(!reader.EndOfStream)

{

InputFile = reader.ReadLine();
//做你想做的事


}

这个ReadLine()函数逐行读取并一次返回一行

为字符串。

" de ********* @ gmail.com"写道:
StreamReader reader = new StreamReader(filePath);//filepatj="C:/aa.txt"
while (!reader.EndOfStream)
{
InputFile = reader.ReadLine();
// do what u want

}
this ReadLine() fuctionread the line by line and return one line at a time
as string.
"de*********@gmail.com" wrote:

我是一个初学者。


我需要逐行读取TXT文件


怎么做?

I am a beginer.

I need to read a TXT file line by line

How to do it?


这篇关于逐行读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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