byte[]和文件FileStream相互转化
来源:互联网 发布:旺道网站排名优化 编辑:程序博客网 时间:2024/06/17 03:20
using System.IO;//读filename到byte[] private byte[] ReadFile(string fileName) { FileStream pFileStream = null; byte[] pReadByte = new byte[0]; try { pFileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(pFileStream); r.BaseStream.Seek(0, SeekOrigin.Begin); //将文件指针设置到文件开 pReadByte = r.ReadBytes((int)r.BaseStream.Length); return pReadByte; } catch { return pReadByte; } finally { if (pFileStream != null) pFileStream.Close(); } } //写byte[]到fileName private bool writeFile(byte[] pReadByte, string fileName) { FileStream pFileStream = null; try { pFileStream = new FileStream(fileName, FileMode.OpenOrCreate); pFileStream.Write(pReadByte, 0, pReadByte.Length); } catch { return false; } finally { if (pFileStream != null) pFileStream.Close(); } return true; } //测试 private void button6_Click(object sender, EventArgs e) { //by 闫磊 Email:Landgis@126.com,yanleigis@21cn.com 2007.11.23 byte[] b = ReadFile(@"c:\u.jpg"); if (writeFile(b, @"c:\u1.jpg")) MessageBox.Show("成功"); elseMessageBox.Show("失败"); }
0 0
- C# byte[]和文件FileStream相互转化
- byte[]和文件FileStream相互转化
- C# byte[]和文件FileStream相互转化
- Java byte数组和文件相互转换
- byte数组和文件读写
- BipMap.byte[],drawable相互转化
- Bitmap,byte[],Drawable相互转化
- Bitmap,byte[],Drawable相互转化
- Bitmap,byte[],Drawable相互转化
- String和byte[]相互转化
- Bitmap,byte[],Drawable相互转化
- byte[]与ByteBuffer相互转化
- byte[] 和文件之间的转换(总结)
- byte数组和文件互相转换
- string 与 byte[] 的相互转化
- CString与Byte数组的相互转化
- android----Bitmap / Drawable / byte[] 之间相互转化
- File,byte,Object之间的相互转化
- java&数据库字符串
- 黑马程序员-JAVA反射机制
- IDA* UVA 1505 - Flood-it!
- ssl运行机制中,为什么不直接采用pms作为会话密钥
- VC6写的 MemoryInfo
- byte[]和文件FileStream相互转化
- OpenGL4.x学习之搭建基于Qt和OpenGL4.x的框架
- 调优的基本选项
- JSP是什么?
- 新生活的开始
- 通过企业分布式缓存共享运行时数据
- 程序员人生之路(强烈推荐,分析的透彻!)
- 2013个人总结
- JSP常规语法