我必须处理csv文件上传的某些限制:
包装器C#代码:
using (var stream = File.OpenRead("C:\~~~\~~~\~~~\SampleFile.csv"))
{
//CSV Header removal snippet - which gives me a new stream containing data without headers.
~
~
~
~
//All my stream handling code of chunking stream into 100mb and then uploading each chunk to azure storage (which is not part of this question)
}
现在我已经知道了-我可以简单地删除使用库就像一个CSV文件的标题- CSVHelper
(如何写数据时,以CSV排除头)
使用上述方法,我可以创建文件的无标头副本,并将新文件读为FileStream-但问题是我正在处理大型文件,并且仅为了删除标头而制作文件副本将是占用空间的工作。
因此,这是我第一次在StackOverflow中问一个问题,以找到解决上述问题的好方法。我希望我能够清楚地解释这个问题。
这应该设法找到第一行的结尾。
using (var stream = File.OpenRead("~~filepath~~"))
using (var reader = new StreamReader(stream))
{
string line = null;
if ((line = reader.ReadLine()) != null)
{
stream.Position = line.Length + 2;
// The 2 is for NewLine(\r\n)
}
//All my stream handling code of chunking stream into 100mb and then uploading each chunk to azure storage (which is not part of this question)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句