Skip to content

Latest commit

 

History

History
309 lines (203 loc) · 9.25 KB

FileObject.rst

File metadata and controls

309 lines (203 loc) · 9.25 KB

FileObject

This class is responsible opening, reading, creating, and saving file contents.

Inherit:

SimObject

Description

FileObject acts as the interface with OS level files. You create a new FileObject and pass into it a file's path and name. The FileObject class supports three distinct operations for working with files:

Before you may work with a file you need to use one of the three above methods on the FileObject.

Example:

// Create a file object for writing
%fileWrite = newFileObject();

// Open a file to write to, if it does not exist it will be created
%result = %fileWrite.OpenForWrite("./test.txt");

if ( %result )
{
   // Write a line to the text files
   %fileWrite.writeLine("READ. READ CODE. CODE");
}

// Close the file when finished
%fileWrite.close();

// Cleanup the file object
%fileWrite.delete();


// Create a file object for reading
%fileRead = newFileObject();

// Open a text file, if it exists
%result = %fileRead.OpenForRead("./test.txt");

if ( %result )
{
   // Read in the first line
   %line = %fileRead.readline();

   // Print the line we just readecho(%line);
}

// Close the file when finished
%fileRead.close();

// Cleanup the file object
%fileRead.delete();

Methods