StreamResourceInfo text = Application.GetResourceStream(new Uri("txt/访问总人数.txt", UriKind.RelativeOrAbsolute));
using(StreamReader read = new StreamReader(text.Stream))
{
string line = read.ReadLine()
read.Close();
}
这样子是没有问题的,可以读取。
但是写入这样写就有问题了,抛出异常:
StreamResourceInfo text = Application.GetResourceStream(new Uri("txt/访问总人数.txt", UriKind.RelativeOrAbsolute));
using(StreamWriter writer = new StreamWriter(text.Stream))
{
writer.WriteLine("2");
writer.Close();
这是为什么呢
}
------解决方案--------------------------------------------------------
指定一个编码方式试试:
using(StreamWriter writer = new StreamWriter(text.Stream,Encoding.GetEncoding("GB2312")))
------解决方案--------------------------------------------------------
非用户执行的代码 不能执行