Io.new Method

Creates a new instance of the Io class.

Syntax

public void new(str filename, str mode)

Run On

Called

Parameters

  • filename
    Type: str
    The name of the file to open.
  • mode
    Type: str
    The mode in which the file should be opened.

Remarks

The mode parameter can be one of the following modes:

  • R – read

  • W – write

  • A – append (implies W)

  • T – translate (text)

  • B – binary

A run-time error occurs if the file is accessed with a method that does not correspond to the current opened mode (for example, if an attempt is made to write to a read-mode file).

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 Io class to write to ExampleFile.

void IoExample() 
{ 
    Io io; 
    container con; 
    FileIoPermission perm; 
    #define.ExampleFile(@"c:\test.txt") 
    #define.ExampleOpenMode("w") 
  
    // Grants permission to execute the 
    // Io.new method. 
    // Io.new runs under code access security. 
    perm = new FileIoPermission(#ExampleFile, #ExampleOpenMode); 
    if (perm == null) 
    { 
        return; 
    } 
    perm.assert(); 
  
    io = new Io(#ExampleFile, #ExampleOpenMode); 
    if (io != null) 
    { 
        io.write("Test"); 
    } 
    // Close the code access permission scope. 
    CodeAccessPermission::revertAssert(); 
}

See Also

Reference

Io Class