标签:
我的想法是首先把base64存入MemoryStream中然后用 FileStream保存,但是当代码写好运行到byte[] b = stream.GetBuffer();这句的时候报错:无法访问 MemoryStream 的内部缓冲区。然后我就给改成了 byte[] b = stream.ToArray();程序就正常了
贴出我的全部demo,共同交流
public void Base64StringToFile(string strbase64, string strurl) { try { strbase64 = strbase64.Replace(‘ ‘, ‘+‘); MemoryStream stream = new MemoryStream(Convert.FromBase64String(strbase64)); FileStream fs = new FileStream(strurl, FileMode.OpenOrCreate, FileAccess.Write); byte[] b = stream.ToArray(); //byte[] b = stream.GetBuffer(); fs.Write(b, 0, b.Length); fs.Close(); } catch (Exception e) { } }
标签:
原文地址:http://www.cnblogs.com/xiaonanclimber/p/4712831.html