Currently Being Moderated
Feb 23, 2009 2:45 PM
Hello everyone,
I am trying to copy a binary file using a bit by bit method
(I'm going to modify the file's code in future, that's why I want
to use such method).
My code is:
var fmsInstallerFile:File =
File.applicationDirectory.resolvePath("bin\\sth.exe");
var fmsInstallerStream:FileStream = new FileStream();
fmsInstallerStream.open(fmsInstallerFile, FileMode.READ);
var file:File =
File.desktopDirectory.resolvePath("coppied.exe");
var stream:FileStream = new FileStream();
stream.open(file, FileMode.WRITE);
var tempByte;
for(var i:int = 0; i <
fmsInstallerStream.bytesAvailable-1; i ++)
{
fmsInstallerStream.position = i;
tempByte = fmsInstallerStream.readByte();
stream.writeByte(tempByte);
}
stream.close();
I don't know why, but this method is not working as it
should. I cannot execute the coppied file, and its size is nearly
half of the original one. What is wrong in my code?
Thank you in advance for any reply.