php二进制保存到本地,C# 将二进制字符串保存到本地
C# 將二進制字符串保存到本地#region 將文件保存到本地
///
/// 將文件保存到本地
///
/// 文件的二進制數(shù)據(jù)字符串
/// 文件名稱,必須帶后綴
private void SaveFile(string psContent, string psFileName)
{
byte[] accessory = Convert.FromBase64String(psContent);
//System.AppDomain.CurrentDomain.BaseDirectory獲取程序的基目錄
string vsAccessoryPath = System.AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + '\\' + psFileName;
FileStream fileStream = null;
try
{
//File.Create Method (String):Creates or overwrites a file in the specified path.
fileStream = File.Create(vsAccessoryPath);
}
catch (System.IO.IOException e)
{
}
//FileStream.Write Method:Writes a block of bytes to the file stream.
fileStream.Write(accessory, 0, accessory.Length);
//FileStream.Flush 方法:清除該流的所有緩沖區(qū),使得所有緩沖的數(shù)據(jù)都被寫入到基礎設備。
fileStream.Flush();
//FileStream.Close Method:Closes the file and releases any resources associated with the current file stream.
fileStream.Close();
}
#endregion
假如文件流保存在數(shù)據(jù)庫中:
string vsSql = "";//從數(shù)據(jù)庫中獲取待轉(zhuǎn)換保存文件的內(nèi)容(比如,之前把文件轉(zhuǎn)換為字節(jié)流保存到數(shù)據(jù)庫中了)
DataSet dsContent = 獲取DataSet的數(shù)據(jù)庫操作;
byte[] vbContent = (byte[])(dsContent.Tables[0].Rows[0]["數(shù)據(jù)庫中保存文件內(nèi)容的列名"]);
string vsContent = Convert.ToBase64String(vbContent);
字節(jié)流保存在數(shù)據(jù)庫中的樣子:
以上就是C# 將二進制字符串保存到本地的內(nèi)容,更多相關(guān)內(nèi)容請關(guān)注PHP中文網(wǎng)(www.php.cn)!
本文原創(chuàng)發(fā)布php中文網(wǎng),轉(zhuǎn)載請注明出處,感謝您的尊重!
總結(jié)
以上是生活随笔為你收集整理的php二进制保存到本地,C# 将二进制字符串保存到本地的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 老马6开后备箱仪表灯不亮?
- 下一篇: HTML5链接tcpUDP,UDP/TC