posts - 609,  comments - 13,  views - 64万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
c
复制代码
/// <summary>
/// 复制资源文件(/Resources/Raw/)
/// </summary>
/// <param name="resourceFileName">资源文件名</param>
public async static Task CopyFileFromResource(string resourceFileName)
{
    //FileSystem.Current.AppDataDirectory 程序文件目录
    string filePath = System.IO.Path.Combine(FileSystem.Current.AppDataDirectory, resourceFileName);
    if (File.Exists(filePath))
    {
        File.Delete(filePath);
    }
    //资源文件是否存在
    bool resExists = await FileSystem.Current.AppPackageFileExistsAsync(resourceFileName);
    if (resExists)
    {
        //资源文件流
        using System.IO.Stream fileStream = await FileSystem.Current.OpenAppPackageFileAsync(resourceFileName);
        // 缓冲区为10k
        byte[] buffer = new Byte[10000];
        // 文件长度
        int length;
        //目标文件流
        using System.IO.FileStream fs = new System.IO.FileStream(filePath, FileMode.OpenOrCreate);
        //循环写入
        do
        {
            length = fileStream.Read(buffer, 0, 10000);
            fs.Write(buffer, 0, length);
            buffer = new Byte[10000];
        } while (length > 0);
        //刷新缓存,结束。
        fs.Flush();
    }
}
复制代码

 

posted on   邢帅杰  阅读(24)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
历史上的今天:
2018-01-26 css背景图充满屏幕
点击右上角即可分享
微信分享提示