using System;
using System.IO;
using System.Threading.Tasks;
using System.Xml.Serialization;
using Windows.Storage;
using Windows.Storage.Streams;
public static class FileReader
{
/// <summary>
/// sample.fileの内容はTに変換する
/// </summary>
/// <returns></returns>
public static async Task<T> SampleAsyncFunc()
{
Uri uri = new Uri("ms-appx:///sample.file");
StorageFile file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri);
IRandomAccessStream randomAccessStream = await file.OpenAsync(FileAccessMode.Read);
Stream stream = randomAccessStream.AsStream();
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
return (T)xmlSerializer.Deserialize(stream);
}
}
UWP-文件读取
最新推荐文章于 2021-09-01 11:52:32 发布