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);
}

 

posted @ 2017-06-02 10:43  Kunkka_An  阅读(581)  评论(0编辑  收藏  举报