第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將文件從程序集資源流寫入磁盤

將文件從程序集資源流寫入磁盤

慕尼黑的夜晚無繁華 2019-10-18 14:36:36
我似乎找不到比以下方法更有效的方法來將嵌入式資源“復(fù)制”到磁盤:using (BinaryReader reader = new BinaryReader(    assembly.GetManifestResourceStream(@"Namespace.Resources.File.ext"))){    using (BinaryWriter writer        = new BinaryWriter(new FileStream(path, FileMode.Create)))    {        long bytesLeft = reader.BaseStream.Length;        while (bytesLeft > 0)        {            // 65535L is < Int32.MaxValue, so no need to test for overflow            byte[] chunk = reader.ReadBytes((int)Math.Min(bytesLeft, 65536L));            writer.Write(chunk);            bytesLeft -= chunk.Length;        }    }}似乎沒有更直接的方法來進行復(fù)制,除非我丟失了某些東西...
查看完整描述

3 回答

?
慕田峪9158850

TA貢獻1794條經(jīng)驗 獲得超7個贊

資源(文件)是否為二進制。


File.WriteAllBytes("C:\ResourceName", Resources.ResourceName);

并且如果資源(文件)是文本。


 File.WriteAllText("C:\ResourceName", Resources.ResourceName);


查看完整回答
反對 回復(fù) 2019-10-18
?
拉丁的傳說

TA貢獻1789條經(jīng)驗 獲得超8個贊

實際上,我最終只使用了這一行: Assembly.GetExecutingAssembly().GetManifestResourceStream("[Project].[File]").CopyTo(New FileStream(FileLocation, FileMode.Create))。當(dāng)然,這是針對.Net 4.0


更新:我發(fā)現(xiàn)上面的行可能保持文件鎖定,以便SQLite報告該數(shù)據(jù)庫是只讀的。因此,我得出以下結(jié)論:


Using newFile As Stream = New FileStream(FileLocation, FileMode.Create)

    Assembly.GetExecutingAssembly().GetManifestResourceStream("[Project].[File]").CopyTo(newFile)

End Using


查看完整回答
反對 回復(fù) 2019-10-18
  • 3 回答
  • 0 關(guān)注
  • 564 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號