zoukankan      html  css  js  c++  java
  • UWP 文件读写API

    1. 读取普通Pictures下面文件:

    public async Task ShowFileContent(string fileName)
    {
        string msgString = "";
        IStorageFolder applicationFolder = KnownFolders.PicturesLibrary;
        IStorageFile file = await applicationFolder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists);
    
        IRandomAccessStream accessStream = await file.OpenReadAsync();
        using (StreamReader streamReader = new StreamReader(accessStream.AsStreamForRead((int)accessStream.Size)))
        {
            string content = streamReader.ReadToEnd();
            if ("" == content)
                msgString = "null";
            else
                msgString = content;
        }
        await new MessageDialog(msgString).ShowAsync();
    }

    2. 读二进制文件,转16进制

    IStorageFolder applicationFolder = KnownFolders.PicturesLibrary;
    IStorageFile file = await applicationFolder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists);
    
    IRandomAccessStream accessStream = await file.OpenReadAsync();
    using (BinaryReader binReader = new BinaryReader(accessStream.AsStreamForRead((int)accessStream.Size)))
    {
        byte[] buffer = new byte[(int)accessStream.Size];
        binReader.Read(buffer, 0, buffer.Length);
    
        string fullString = "";
        for(int i=3;i<buffer.Length;i++)
        {
            fullString += String.Format("{0:X2}", buffer[i]);
        }
        string WifiMAC = fullString.Substring(6,12);
    }
  • 相关阅读:
    021 顺时针打印矩阵
    020 二叉树的镜像
    019 树的子结构
    018 机器人的运动范围
    017 矩阵中的路径
    022 Jquery总结
    003 css总结
    002 html总结
    016 合并两个排序的链表
    015 反转链表
  • 原文地址:https://www.cnblogs.com/kunkka/p/6932204.html
Copyright © 2011-2022 走看看