开发者

file is not read by completely [closed]

开发者 https://www.devze.com 2023-04-10 16:38 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and 开发者_运维问答 cannot be reasonably answered in its current for
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and 开发者_运维问答 cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have an file text with approximate 113687 lines, but my application reads only 314 lines, can anyone say why?

My code:

string file = @"z:\foo.txt";
StreamReader reader = File.OpenText(file);
string line;
int rows = 0; 
while ((line = reader.ReadLine()) != null) {
  ++rows; 
   doSomethingWith(line); 
  // ...
} 

The DoSomethingWith function is similar to:

protected static bool DoSomethingWith(string line)
{
    return Regex.Match(line, @"\d+\-\d+\.\d+\.\d+\.\d+").Success; 
}

Updated:

In answer to Gregs question:

Does your foo.txt contain a Ctrl+Z character on line 314?

Yes, my file contains a Control-Z character on line 314.


Text files on Windows can be terminated with a Ctrl+Z character. This means that when the file is read, the StreamReader returns end-of-file when the Ctrl+Z is encountered. Any data following the Ctrl+Z is not read.

If you wish to read the entire file without this text-mode behaviour, use File.OpenRead instead of File.OpenText.

0

精彩评论

暂无评论...
验证码 换一张
取 消