Jump to content
Sign in to follow this  

How FileWrite write Binary Data into file

Recommended Posts


$file = FileOpen("tmp.txt", 18)         ;binary mode, I try 17 too
If $file = -1 Then
    MsgBox(0, "error", "can't open file.")

$chars = FileRead($file)                    ;$char's content is like 0x1234....
$test = StringReplace($chars, "B2CBB5A5", "D4ADB0E6", 1)           ;replace once use a specified string
FileWrite($file, $test)                 ;can't write, and the tmp.txt is empty now.

This is my test code above. Why filewrite can't work? And HowTO?

I also try $test = StringTrimLeft($chars, 2), but it can't work too.


Share this post

Link to post
Share on other sites

You can not open a file in read and write mode at the same time.

You need to open the file for reading, then close the file after reading.

Then open the file again for writing.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this