我想写个类,将一个上传文件转成字节流返回出去~求高手写个例子给我~

解决方案 »

  1.   


    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就是字节流数组!!
      

  2.   


    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();
      

  3.   

    System.InvalidOperationException: 生成 XML 文档时出错。 ---> System.InvalidOperationException: 此流上不支持超时我传了个xml文件,报了这个错,是不是xml不能转化成字节流?
      

  4.   

    如果用的是asp.net的上传控件,那就用这句:
                byte[] bytInput = this.FileUpload1.FileBytes;
      

  5.   


            [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;
            }我用的是这个,是不是返回的值错了?
      

  6.   

    FileInfo fi = new FileInfo("文件路径");
    FileStream fs = fi.OpenRead();
    byte[] bytes = new byte[fs.Length];
    fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
    fs.close()