這並不工作:使用StreamReader打開資源文件?
string fileContent = Resource.text;
StreamReader read = File.OpenText(fileContent);
string line;
char[] splitChar = "|".ToCharArray();
while ((line = read.ReadLine()) != null)
{
string[] split = line.Split(splitChar);
string name = split[0];
string lastname = split[1];
}
read.Dispose();
如何打開一個資源文件,以獲取其內容是什麼?
什麼是「不工作」意思?它是否會拋出異常?它是否默默地失敗? – 2011-04-08 18:14:27
請參閱:http://stackoverflow.com/questions/5342975/get-a-textreader-from-a-stream/5343005#5343005 – 2011-04-08 18:14:53
資源文件通常是一個二進制文件。用StreamReader讀取它可能不會給你想要的信息。請參閱@Arnaud F.提供的用於從流中讀取文本資源的答案。 – 2011-04-08 18:23:02