文件与base64二进制转换
/// <summary> /// 文件转换为Base64二进制流 /// </summary> /// <param name="FilePath"></param> /// <returns></returns> public static string FileToBase64(string FilePath) { FileStream fileStream = File.Open(FilePath, FileMode.OpenOrCreate); byte[] buffer = new byte[fileStream.Length]; fileStream.Read(buffer, 0, buffer.Length); fileStream.Close(); return Convert.ToBase64String(buffer); }
/// <summary> /// Base64二进制流还原文件 /// </summary> /// <param name="FilePath">存放文件的路径</param> /// <param name="StringBase64">文件Base64二进制流</param> public static void Base64TeCode(string FilePath,string StringBase64) { FileStream fileStream = new FileStream(FilePath, FileMode.Create); byte[] buffer = Convert.FromBase64String(StringBase64); fileStream.Write(buffer, 0, buffer.Length); fileStream.Close(); }
如果您也觉得不错,那就顶下,关注下,谢谢您的支持!!
当大部分人都在关注你飞的高不高时,只有少部分人关心你飞的累不累。