C# 一个 CSV 文件可以包含多少行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14273020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 11:16:26  来源:igfitidea点击:

How many rows can a CSV file contain?

c#

提问by amit

What is the maximum number of rows a CSV file can contain?

CSV 文件最多可以包含多少行?

I would like to know a specific number, as my requirement is to allow the maximum number of entries. Is this number dependent on the operating system, or is the size fixed?

我想知道一个具体的数字,因为我的要求是允许最大数量的条目。这个数字取决于操作系统,还是大小是固定的?

回答by Alexei Levenkov

CSV is text. There no formal restrictions on the file size nor number of colums or rows. Most official specification is RFC4180if you want some "formal" statement.

CSV 是文本。对文件大小、列数或行数没有正式限制。如果您想要一些“正式”声明,大多数官方规范是RFC4180

File system and programs that would read the file can impose own restrictions. I.e. a lot of quickly written tools would not handle files large than 2Gb (integer size limit)...

文件系统和读取文件的程序可以施加自己的限制。即许多快速编写的工具无法处理大于 2Gb(整数大小限制)的文件...

回答by Tilak

Adding to @Alexei answer I would like to specify that you can use BinaryReaderto find total line count (for files greater than 2GB).

添加到@Alexei 答案中,我想指定您可以BinaryReader用来查找总行数(对于大于 2GB 的文件)。

 BinaryReader reader = new BinaryReader(File.OpenRead(@"C:\test.csv"));
 char lastChar = reader.ReadChar();
 char newChar = new char();
 int lineCount = 0;
 do 
 {
    newChar = reader.ReadChar();
    if (lastChar == '\r' && newChar == '\n')
    {  
        lineCount++;
    }
    lastChar = newChar;
 }  while( reader.PeekChar() != -1);