链接:https://stackoverflow.com/questions/48043058/xamarin-forms-read-from-text-file-result-is-null
Stream stream = assembly.GetManifestResourceStream("Mapper.data.txt");
这样直接写读取内容为null, 需要在当前程序集遍历找到那个资源文件,然后再取。
Solution:
var assembly = typeof(MapPage).GetTypeInfo().Assembly;
foreach (var res in assembly.GetManifestResourceNames())
{
if(res.Contains("data.txt"))
{
Stream stream = assembly.GetManifestResourceStream(res);
using (var reader = new StreamReader(stream))
{
string htmlString = reader.ReadToEnd();
}
break;
}
}
网友评论