文件.二进制-转换
http://www.10086bank.com/201332110427316.html
将文件转换成二进制方法:
/// <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;
}
将二进制转换成文件方法:
using System.IO;
string filePath = "D://a.jpg"; //文件路径
byte[] br = ConvertToBinary(filePath);
FileStream fstream = File.Create(filePath, br.Length);
try
{
fstream.Write(br, 0, br.Length); //二进制转换成文件
}
catch(Exception ex)
{
//抛出异常信息
}
finally
{
fstream.Close(); //这里必须有
}
ClickCounts: 51 CommentS: 0
feifei at 2013-3-21 10:04:27.316 do it
The Next:数组中求第K大数(62)