1

Good day!

I try to get all lines from file.

Case: I write some strings into file (some WriteClass) and then try to get all lines frm it. via

var lines=System.IO.File.ReadAllLines(fileName,Encoding.Default);

Bit Count of lines==0! And i havent any exceptions.

What it can be?

Thank you!

4

1 回答 1

0

我也有这个问题。我知道这有点麻烦,但最终导致问题的是我的 URI 格式错误。我把它当作一个字符串来对待,我的解析器在读取行之前尽职地检查文件是否存在。

正确的:

XmlCsvReader reader = new XmlCsvReader(new Uri("file:///C:/Users/Z/Documents/test.csv"), doc.NameTable);

错误的:

XmlCsvReader reader = new XmlCsvReader(new Uri("C:\\Users\\Z\\Documents\\test.csv"), doc.NameTable);

由于 URI 永远不会有效,因此永远不会初始化“行”。我猜你的问题可能就是这种情况。解析器示例如下。

            if (File.Exists(location.AbsolutePath))
        { //this will never run if the URI is formatted wrong
          //The file will never be found

            lines = File.ReadAllLines(location.AbsolutePath);
            Console.WriteLine(lines);
            index = 0;
            column = 0;
            depth = 0;
            tag = 0;
            rs = ReadState.Initial;
        }
于 2016-06-27T01:28:13.100 回答