使用C#分割巨大的CSV文件 [英] Split a huge CSV file using C#
本文介绍了使用C#分割巨大的CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想将一个巨大的2GB csv文件拆分为多个文件.
拆分必须基于记录数
例如1-100000:file1
100001-200000:文件2
200001-300000:文件3
直到记录结束.
感谢您的帮助... !!
谢谢
Venkat.
Hi All,
I want to split a huge 2GB csv file to multiple files.
The split has to be based on the number of records
for eg 1-100000 : file1
100001-200000 : file2
200001-300000 : file3
till end of records.
Thanks for your help...!!
thanks
Venkat.
推荐答案
如果有内存,则可以使用File.ReadLines (string Path)
将所有行读入数组.然后,您可以计算出将它们移到新数组中的行数,并对每个文件执行WriteAllLines(String, String[])
.您可以使用LINQ来获取代码行:
If you have the memory, you can read all the lines into an array usingFile.ReadLines (string Path)
. Then you can figure the number of lines an move them into new arrays and do aWriteAllLines(String, String[])
for each file. You can use LINQ to get the lines:
var x = File.ReadLines(@"C:\temp\connections.xml");
File.WriteAllLines(@"C:\temp\connections2.xml", x.Take(10).ToArray());
在第一个文件之后使用跳过".
Use Skip after the first file.
这篇关于使用C#分割巨大的CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文