Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. FileStream : Problem in Reading File

FileStream : Problem in Reading File

Scheduled Pinned Locked Moved C#
questiondatabasedata-structureshelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zishan Haider
    wrote on last edited by
    #1

    hello, I have a FileStream object in an OnChange event. Everytime OnChange is called, the code goes like this : private void OnChanged(object source, FileSystemEventArgs e) { byte [] data = new byte[100]; try { fs.Read(data,offSet,fs.Length-offSet); offSet = fs.Length; changedText = trim(Encoding.ASCII.GetString(data)); doOperations(changedText); } catch(Exception ee) {} } Now suppose on first OnChange call, 50 bytes were read, filling up the byte array (data) from index 0 to 49. The Problem starts on the next OnChange call. It continues to fill my byte array from 50 onwards, which finally results in the System.ArgumentException, when it reaches the array length 100. I need my byte array to be filled from 0 everytime OnChange is called. How can I do it? regards Zishan

    S 1 Reply Last reply
    0
    • Z Zishan Haider

      hello, I have a FileStream object in an OnChange event. Everytime OnChange is called, the code goes like this : private void OnChanged(object source, FileSystemEventArgs e) { byte [] data = new byte[100]; try { fs.Read(data,offSet,fs.Length-offSet); offSet = fs.Length; changedText = trim(Encoding.ASCII.GetString(data)); doOperations(changedText); } catch(Exception ee) {} } Now suppose on first OnChange call, 50 bytes were read, filling up the byte array (data) from index 0 to 49. The Problem starts on the next OnChange call. It continues to fill my byte array from 50 onwards, which finally results in the System.ArgumentException, when it reaches the array length 100. I need my byte array to be filled from 0 everytime OnChange is called. How can I do it? regards Zishan

      S Offline
      S Offline
      Stanciu Vlad
      wrote on last edited by
      #2

      :) lose the offset thing look at msdn FileStream Read method :

      [C#]
      public override int Read(
      [In,Out] byte[] array,
      int offset,
      int count
      );

      Parameters
      *array
      When this method returns, contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.
      *offset
      The byte offset in array at which to begin reading.
      *count
      The maximum number of bytes to read.
      Return Value
      The total number of bytes read into the buffer. This might be less than the number of bytes requested if that number of bytes are not currently available, or zero if the end of the stream is reached.

      I hope you understand... By the way... visit http://nehe.gamedev.net[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups