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(); } }
标签:文件,resourceFileName,filePath,System,Current,Raw,FileSystem,Resources From: https://www.cnblogs.com/xsj1989/p/17988709