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);
    }
  • 相关阅读:
    Sublime Text 3065
    FBX .NET
    macbook pro的usb串口失效的的处理方法
    CMAKE使用
    Ctrl+Scroll改变所有Editor的缩放比例 (Code::Blocks)
    如何在Mac OSX 10.10上安装GDB
    yum安装指定(特定)版本(旧版本)软件包的方法
    MinGW: TOO MANY SECTIONS issue
    轻量级Image Library
    CodeLite的姿势
  • 原文地址:https://www.cnblogs.com/kunkka/p/6932204.html
Copyright © 2011-2022 走看看