zoukankan      html  css  js  c++  java
  • Metro下读取txt文件

    情况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里面不知道怎么读取文本格式,有知道请留言。

  • 相关阅读:
    C# 小算法1
    函数 y=x^x的分析
    随机数
    对拍
    Cube Stack
    Permutation
    一笔画问题
    康托展开&&康托逆展开
    待完成
    小错误 17/8/10
  • 原文地址:https://www.cnblogs.com/wangjinming/p/4383242.html
Copyright © 2011-2022 走看看