CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Location
    Holy Land
    Posts
    306

    accessing a specific area in a file...?

    How can i access a specific range of characters in file?

    for example I want to open a text file and read from character #39 to character #99.

    Is there a way of doing this without reading the whole file using the FileStream.ReadToEnd() Method, and then accessing the specific characters???
    The ReadToEnd method could take a long time if it's a big file, and i only need a small portion of the file content...
    Rate this post if you found it useful!
    10X, gilly914

  2. #2
    Join Date
    Nov 2003
    Posts
    2,185

    Re: accessing a specific area in a file...?


  3. #3
    Join Date
    Feb 2008
    Posts
    79

    Re: accessing a specific area in a file...?

    Or:
    Code:
            //Create a file stream from an existing file.
            FileInfo fi=new FileInfo("c:\\csc.txt");       
            FileStream fs=fi.OpenRead();
    
            //Read 100 bytes into an array from the specified file.
            int nBytes=100;
            byte[] ByteArray=new byte[nBytes];
            int nBytesRead=fs.Read(ByteArray, 0, nBytes);
            Console.WriteLine("{0} bytes have been read from the specified file.", nBytesRead.ToString());
    Cheers,
    Jon

  4. #4
    Join Date
    Jul 2004
    Location
    Holy Land
    Posts
    306

    Re: accessing a specific area in a file...?

    Thanks!
    I'll try it, and get back to you...
    Rate this post if you found it useful!
    10X, gilly914

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured