问题
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!
回答1:
I was having this issue as well. I know this is somewhat of a necrobump but what ultimately caused the issue was my URI was in the wrong format. I was treating it like a string and my parser was dutifully checking if the file existed before reading lines.
right:
XmlCsvReader reader = new XmlCsvReader(new Uri("file:///C:/Users/Z/Documents/test.csv"), doc.NameTable);
wrong:
XmlCsvReader reader = new XmlCsvReader(new Uri("C:\\Users\\Z\\Documents\\test.csv"), doc.NameTable);
Since the URI would never be valid, 'lines' would never be initialized. I'm guessing this may be the case with your issue. Parser example below.
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;
}
来源:https://stackoverflow.com/questions/22652809/system-io-file-readalllines-returns-zero-strings