如何把文件转成字节流? 我想写个类,将一个上传文件转成字节流返回出去~求高手写个例子给我~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 FileInfo fi = new FileInfo("文件路径");FileStream fs = fi.OpenRead();byte[] bytes = new byte[fs.Length];fs.Read(bytes, 0, Convert.ToInt32(fs.Length));fs.close()bytes就是字节流数组!! FileStream filestream = new FileStream(Application.StartupPath + "a.txt", FileMode.Open, FileAccess.Read);BinaryReader filerd = new BinaryReader(filestream,Encoding .Default );byte[] filebyte = new byte[filestream.Length];filerd.Read(filebyte, 0, (int)filestream.Length);filerd.Close();filestream.Close(); System.InvalidOperationException: 生成 XML 文档时出错。 ---> System.InvalidOperationException: 此流上不支持超时我传了个xml文件,报了这个错,是不是xml不能转化成字节流? 如果用的是asp.net的上传控件,那就用这句: byte[] bytInput = this.FileUpload1.FileBytes; [WebMethod] public FileStream SetXmlStream() { FileInfo fi = new FileInfo("C:/123.xml"); FileStream fs = fi.OpenRead(); byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, Convert.ToInt32(fs.Length)); return fs; }我用的是这个,是不是返回的值错了? FileInfo fi = new FileInfo("文件路径");FileStream fs = fi.OpenRead();byte[] bytes = new byte[fs.Length];fs.Read(bytes, 0, Convert.ToInt32(fs.Length));fs.close() 给出用户名和密码,谁给做个模拟登陆? 这段psql语句是什么意思?求高手! 关于DrawImage的问题.. Forms控件treeView的问题,为什么添加Node.Tag输出看全部是一样,而且是最后一个添加的值 Web 访问数据库出现SQL Server 不存在或访问被拒绝。 求学习心得:菜鸟编程时总要翻书,不知大侠们是如何成长的? 冒泡排序法理解问题,请指教啊 winform窗体同步数据 请问怎么为form的右上角的关闭按扭编写代码? 我是个初学者,请问...... 关于datawindow.net 2.5 串口数据监听的问题SerialPort
FileInfo fi = new FileInfo("文件路径");
FileStream fs = fi.OpenRead();
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
fs.close()bytes就是字节流数组!!
FileStream filestream = new FileStream(Application.StartupPath + "a.txt", FileMode.Open, FileAccess.Read);
BinaryReader filerd = new BinaryReader(filestream,Encoding .Default );
byte[] filebyte = new byte[filestream.Length];
filerd.Read(filebyte, 0, (int)filestream.Length);
filerd.Close();
filestream.Close();
byte[] bytInput = this.FileUpload1.FileBytes;
[WebMethod]
public FileStream SetXmlStream()
{
FileInfo fi = new FileInfo("C:/123.xml");
FileStream fs = fi.OpenRead();
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
return fs;
}我用的是这个,是不是返回的值错了?
FileStream fs = fi.OpenRead();
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
fs.close()