这不起作用:
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();
如何打开资源文件以获取其内容?
答案 0 :(得分:5)
试试这样:
string fileContent = Resource.text;
using (var reader = new StringReader(fileContent))
{
string line;
while ((line = reader.ReadLine()) != null)
{
string[] split = line.Split('|');
string name = split[0];
string lastname = split[1];
}
}
答案 1 :(得分:0)
我认为变量fileContent已经包含了你需要的所有内容。
答案 2 :(得分:0)
要读取资源,需要一个名为“ResourceReader”的特殊Stream,你可以像这样使用它:
string fileContent = "<your resource file>";
using (ResourceReader reader = new ResourceReader(fileContent))
{
foreach (IDictionaryEnumerator dict in reader)
{
string key = dict.Key as string;
object val = dict.Value;
}
}