本文介绍了流处理之前EndOfData是真实的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个连接到FTP的方法,读取csv文件到流然后使用TextFieldParser来处理数据。



一切正常,除了我得到,当它通过阅读CSV大约一半得到一个问题,突然我得到一个的ObjectDisposedException例外。我试图通过这两个StreamReader的&放大器;的TextReader将使用TextFieldParser但无论结果同样的问题。



我应该下载CSV到一个临时的本地目录,然后读取或者没有问题,读文件从FTP?我想可能有一些服务器设置可能超时流读取整个文件之前。

 的FtpWebRequest请求=(的FtpWebRequest) FtpWebRequest.Create(REMOVED.csv); 
request.Credentials =新的NetworkCredential(XYZ,*******);使用使用(流流= response.GetResponseStream())(WebResponse的响应= request.GetResponse())
{

{
使用(TextReader的读者
=新StreamReader的使用(流))
{
(TextFieldParser分析器=新的TextFieldParser(阅读器))
{
parser.HasFieldsEnclosedInQuotes = TRUE;
parser.Delimiters =新的字符串[] {,};
,而(!parser.EndOfData)//异常被抛出这里大约1500lines成CSV
{
Console.WriteLine(parser.ReadLine()的ToString());
}
}
}
}
}



If I should be downloading the file first, do I just use WebClient.DownloadFile() ?? How can I tell when the file has finished downloading to then read it?

EDIT:

System net tracing output shows the following

FURTHER EDIT

The output from System.Net Tracing shows the last line of the CSV being received, so why is the parser being Disposed before it finishes?? I'm still quite new to programming so I'm not really sure how to proceed

解决方案

So I was unable to figure out how to stop the stream disposing before I read to the end with my TextFieldParser, instead I did the following:

This isn't very elegant but if anyone else comes across the above error know that downloading the file is an alternative.

这篇关于流处理之前EndOfData是真实的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 17:42
查看更多