Reading a .exe file and copying to another location........
Hi -
I want to develop an application, which reads from source file,and paste it to the destination file...
I want to read only 1024 Bytes at a time, and paste it to another location...
The code is :
------
private const string FILE_NAME = "Sample.txt";
public static void Main(String[] args)
{
FileStream fs = File.Create("Sample1.txt");
FileStream sr = File.Open (FILE_NAME,FileMode.Open,FileAccess.Read,FileShare.Read);
byte[] b = new byte[1024];
int variable = 0, tempVariable = 0;
while ( (tempVariable = sr.Read(b,0,b.Length)) > 0)
{
//fs.Write(b,variable,tempVariable);
fs.Write(b,0,variable);
variable += tempVariable;
}
Console.WriteLine ("The end of the stream has been reached.");
sr.Close();
fs.Close();
}
The code is giving me the error:
Offset and length are out of bounds.
If I read the full bytes and write full bytes , it is working... but I want to read 1024 bytes at a time......
Thanx in advance,
dwurity
[1165 byte] By [
dwurity] at [2007-11-19 10:00:06]

# 1 Re: Reading a .exe file and copying to another location........
Thanx for support...... I have got...
The mistake is ... I havent used the seek pointer.....
Hi -
I want to develop an application, which reads from source file,and paste it to the destination file...
I want to read only 1024 Bytes at a time, and paste it to another location...
The code is :
------
private const string FILE_NAME = "Sample.txt";
public static void Main(String[] args)
{
FileStream fs = File.Create("Sample1.txt");
FileStream sr = File.Open (FILE_NAME,FileMode.Open,FileAccess.Read,FileShare.Read);
byte[] b = new byte[1024];
int variable = 0, tempVariable = 0;
while ( (tempVariable = sr.Read(b,0,b.Length)) > 0)
{
//fs.Write(b,variable,tempVariable);
fs.Write(b,0,variable);
variable += tempVariable;
}
Console.WriteLine ("The end of the stream has been reached.");
sr.Close();
fs.Close();
}
The code is giving me the error:
Offset and length are out of bounds.
If I read the full bytes and write full bytes , it is working... but I want to read 1024 bytes at a time......
Thanx in advance,
dwurity