Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Creates an instance of the .
Syntax
public void new(str filename, str mode)
Run On
Called
Parameters
- filename
Type: str
The name of the file to open for this instance of the BinaryIo class.
- mode
Type: str
The mode used to create this instance of the BinaryIo class.
Remarks
If an attacker can control input to the new method, a security risk exists. Therefore, this method runs under Code Access Security. Calls to this method on the server require permission from the . Ensure that the user has development privileges by setting the security key to SysDevelopment on the control that calls this method.
Examples
This example uses the BinaryIo class to read data from the ExampleFile text file.
static void BinaryIoExampleW2(Args _args){ #define.ExampleFile(@"D:\Writers\GeneMi\_Junk\TestW.BinaryIo") #define.ExampleOpenModeW("w") #define.ExampleOpenModeR("r") BinaryIo binaryIoObject; container con1; str sConRecs; FileIoPermission perm; // Set the code access permission to help protect the use of // the BinaryIo.new method. perm = new FileIoPermission(#ExampleFile, #ExampleOpenModeW); if (perm == null) { return; } perm.assert(); // Overwrites the file if it already exists; restarts it as empty. binaryIoObject = new BinaryIo(#ExampleFile, #ExampleOpenModeW); if (binaryIoObject != null) { info("w binaryIoObject is NOT null, Good."); binaryIoObject.write("hello world"); binaryIoObject.write("goodbye solar system"); } else { warning("w binaryIoObject is NULL, Bad."); } binaryIoObject.finalize(); binaryIoObject = null; // Close the file, w? // BinaryIo instance can only read files in that // are in the exact same esoteric format that BinaryIo // writes files to. // binaryIoObject = new BinaryIo(#ExampleFile, #ExampleOpenModeR); if (binaryIoObject != null) { info("r binaryIoObject is NOT null, Good."); while (true) { con1 = binaryIoObject.read(); if (con1 == conNull()) { info("r, no more records."); break; } sConRecs = con2Str(con1); info(sConRecs); } } else { warning("r binaryIoObject is NULL, Bad."); } binaryIoObject.finalize(); binaryIoObject = null; WINAPI::deleteFile(#ExampleFile); // Clean up after the job. CodeAccessPermission::revertAssert(); }/*** Output copied from Infolog:Message (11:22:16 am)w binaryIoObject is NOT null, Good.r binaryIoObject is NOT null, Good.hello worldgoodbye solar systemr, no more records.***/