Topic: version 4 MAXScript Language Improvements/Language Improvements
BinStream fopen <String fileName> <String mode>
Opens a file for reading or writing based on the mode parameter. This can either be "wb" for Writing Binary or "rb" for Reading Binary. The function will return a BinStream value.
Boolean FClose <BinStream>
Close a BinStream value. Returns True if it successfully closed the BinStream.
Boolean fseek <BinStream> <Integer> <#seek_set | #seek_cur | #seek_end>
Move the file pointer to the specified location based off the seek parameter.
#seek_set - base off start of file.
#seek_cur - base off current position.
#seek_end - base off end of file.
Integer ftell <BinStream>
Returns the current file pointer position.
Boolean WriteByte <BinStream> <Integer> [#signed | #unsigned]
Writes a Integer to the file as one byte. Returns True if write was successful.
Boolean WriteShort <BinStream> <Integer> [#signed | #unsigned]
Writes a Integer to the file as two bytes. Returns True if write was successful.
Boolean WriteLong <BinStream> <Integer> [#signed | #unsigned]
Writes a Integer to the file as four bytes. Returns True if write was successful.
Boolean WriteFloat <BinStream> <Float>
Writes a Float to the file as four bytes. Returns True if write was successful.
Boolean WriteString <BinStream> <String>
Writes a string to the file. Returns True if write was successful.
Integer ReadByte <BinStream> [#signed | #unsigned]
Read a one byte value and return as an Integer.
Integer ReadShort <BinStream> [#signed | #unsigned]
Read a two byte value and return as an Integer.
Integer ReadLong <BinStream> [#signed | #unsigned]
Read a four byte value and return as an Integer.
Float ReadFloat <BinStream>
Read a four byte value and return as an Float.
String ReadString <BinStream>
Read a string from the file.
Example:
f=fopen "c:\\test.bin" "wb"
WriteString f "String"
WriteByte f 64
WriteShort f 128
WriteLong f 256
WriteFloat f 512.0
WriteString f "gnirtS"
WriteLong f (ftell f)
fclose f
f=fopen "c:\\test.bin" "rb"
ReadString f
ReadByte f
ReadShort f
ReadLong f
ReadFloat f
ReadString f
ftell f
ReadLong f
fclose f
See also