我看过许多示例,显示StreamReader采用了“Properties.Resources.someTextFile”,显然它们工作得很好。但是,在.net 4.5中,我仍然得到:
//while not end of file, read lines of file and split into array
string myFile = Properties.Resources.data;
string line;
StreamReader reader = new StreamReader(myFile);
while ((line = reader.ReadLine()) != null)
{
string[] array = line.Split('#');
string tickerSymbol = array[0];
string regPattern = array[1];
...
那么,我做错了什么?
答案 0 :(得分:2)
通过Properties.Resources访问数据文本文件资源,生成的变量myFile应该包含文件的字符串内容。
string myFile = Properties.Resources.data;
var lines = myFile.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
foreach(var line in lines)
{
// Process each line...
}