情况1:txt是Utf8格式的。

读取代码:IList<String> lines = await Windows.Storage.FileIO.ReadLinesAsync(file);//正常读取

 

情况2:txt不是utf8格式的,比如GB2312格式。

using (var stream = await file.OpenAsync(FileAccessMode.Read))
{

    Encoding encoding = Encoding.GetEncoding("GB2312");

    StreamReader reader = new StreamReader(stream.AsStream(), encoding);

    char[] chars = new char[stream.Size];      

    reader.ReadAsync(chars, 0, chars.Length); 

    string text= new string(chars);//转成string

}

这个必须知道文本的格式,不然的话没办法。Metro里面不知道怎么读取文本格式,有知道请留言。

相关文章:

  • 2021-06-01
  • 2021-08-16
  • 2021-11-22
  • 2021-11-11
  • 2021-11-11
  • 2021-09-07
  • 2021-11-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-17
  • 2021-11-14
  • 2021-11-30
  • 2021-11-30
  • 2021-07-07
相关资源
相似解决方案