Torque3D Documentation / _generateds / FileStreamObject

FileStreamObject

consoledoc.h

A wrapper around StreamObject for parsing text and data from files.

More...

Public Functions

void

Close the file. You can no longer read or write to it unless you open it again.

bool
open(string filename, string openMode)

Open a file for reading, writing, reading and writing, or appending.

Detailed Description

A wrapper around StreamObject for parsing text and data from files.

FileStreamObject inherits from StreamObject and provides some unique methods for working with strings. If you're looking for general file handling, you may want to use FileObject.

// Create a file stream object for reading
%fsObject = new FileStreamObject();

// Open a file for reading
%fsObject.open("./test.txt", "read");

// Get the status and print it
%status = %fsObject.getStatus();
echo(%status);

// Always remember to close a file stream when finished
%fsObject.close();

see:

StreamObject for the list of inherited functions variables

see:

FileObject for general file handling.

Public Functions

close()

Close the file. You can no longer read or write to it unless you open it again.

// Create a file stream object for reading
%fsObject = new FileStreamObject();

// Open a file for reading
%fsObject.open("./test.txt", "read");

// Always remember to close a file stream when finished
%fsObject.close();

see:

open(string filename, string openMode)

Open a file for reading, writing, reading and writing, or appending.

Using "Read" for the open mode allows you to parse the contents of file, but not making modifications. "Write" will create a new file if it does not exist, or erase the contents of an existing file when opened. Write also allows you to modify the contents of the file.

"ReadWrite" will provide the ability to parse data (read it in) and manipulate data (write it out) interchangeably. Keep in mind the stream can move during each operation. Finally, "WriteAppend" will open a file if it exists, but will not clear the contents. You can write new data starting at the end of the files existing contents.

Parameters:

filename

Name of file to open

openMode

One of "Read", "Write", "ReadWrite" or "WriteAppend"

// Create a file stream object for reading
%fsObject = new FileStreamObject();

// Open a file for reading
%fsObject.open("./test.txt", "read");

// Get the status and print it
%status = %fsObject.getStatus();
echo(%status);

// Always remember to close a file stream when finished
%fsObject.close();

return:

True if the file was successfully opened, false if something went wrong