/// <summary>
/// 把文件转化为二进制流
/// </summary>
/// <param name="Path"></param>
/// <returns></returns>
public static byte[] ConvertToBinary(string Path)
{
FileStream stream = new FileInfo(Path).OpenRead();
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
return buffer;
}
/// <summary>
/// 把二进制流转化为文件
/// </summary>
public static void GetFile()
{
string filePath = "D://a.jpg"; //文件路径
//二进制流数据 br
byte[] br = ConvertToBinary(filePath);
FileStream fstream = File.Create(filePath, br.Length);
try
{
fstream.Write(br, 0, br.Length); //二进制转换成文件
}
catch (Exception ex)
{
//抛出异常信息
}
finally
{
fstream.Close();
}
}