FileStream : Problem in Reading File
-
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
-
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
:) 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[^]