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