C# 將檔案轉化成byte[]陣列
阿新 • • 發佈:2019-02-17
/// <summary>
/// 檔案轉化成byte[]陣列
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
private byte[] FileContent(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
try
{
byte[] buffur = new byte[fs.Length];
fs.Read(buffur, 0, (int)fs.Length);
return buffur;
}
catch (Exception ex)
{
MessageBoxHelper.ShowPrompt(ex.Message);
return null;
}
finally
{
if (fs != null)
{
fs.Close();
}
}
}
/// 檔案轉化成byte[]陣列
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
private byte[] FileContent(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
try
{
byte[] buffur = new byte[fs.Length];
fs.Read(buffur, 0, (int)fs.Length);
return buffur;
}
catch (Exception ex)
{
MessageBoxHelper.ShowPrompt(ex.Message);
return null;
}
finally
{
if (fs != null)
{
fs.Close();
}
}
}