+ -
当前位置:首页 → 问答吧 → asp.net 使用ajax

asp.net 使用ajax

时间:2010-12-14

来源:互联网

我在网上看到一个例子http://blog.csdn.net/ljy090811/archive/2010/03/04/5346405.aspx,照着做了一下,一切正常,之后把例子的后台函数替换成我的代码:
OpenFile(int start, int length)
 try
  {
  fs = new FileStream(strFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
  PlayStreams = new byte[length];// i = (int)fs.Length;
  fs.Seek(start, SeekOrigin.Current);
  read = fs.Read(PlayStreams, 0, length);
  // sChar = Encoding.ASCII.GetChars(PlayStreams);
  // i++;
  aaaa = Encoding.UTF8.GetString(PlayStreams);

  }
  catch
  {
  }
  fs.Close();
  return aaaa;

我发现,当我读取起始值start为0时的文件,js输出为空,当start为40或其他值的时候就是具体值,这是为什么

作者: yan20054517   发布时间: 2010-12-14

C# code

using System;
using System.IO;

class FStream
{
    static void Main()
    {
        const string fileName = "Test#@@#.dat";

        // Create random data to write to the file.
        byte[] dataArray = new byte[100000];
        new Random().NextBytes(dataArray);

        using(FileStream  
            fileStream = new FileStream(fileName, FileMode.Create))
        {
            // Write the data to the file, byte by byte.
            for(int i = 0; i < dataArray.Length; i++)
            {
                fileStream.WriteByte(dataArray[i]);
            }

            // Set the stream position to the beginning of the file.
            fileStream.Seek(0, SeekOrigin.Begin);

            // Read and verify the data.
            for(int i = 0; i < fileStream.Length; i++)
            {
                if(dataArray[i] != fileStream.ReadByte())
                {
                    Console.WriteLine("Error writing data.");
                    return;
                }
            }
            Console.WriteLine("The data was written to {0} " +
                "and verified.", fileStream.Name);
        }
    }
}


作者: yhtapmys   发布时间: 2010-12-14

我也遇到过 楼主相同的问题!!!filestream读取的时候貌似是从1开始的 我个人理解是这样 改成1和以后的值都没有问题

作者: pm90125   发布时间: 2010-12-14

热门下载

更多