File

File operations with both static utility methods and instance-based operations.

xxml
Language::IO

Static Methods

MethodParametersReturnsDescription
existspath: String^Bool^True if file exists
deletepath: String^Bool^True if deleted
copysrcPath: String^, dstPath: String^Bool^True if copied
renameoldPath: String^, newPath: String^Bool^True if renamed
sizeOfpath: String^Integer^Size in bytes
readAllpath: String^String^Read entire file content

Instance Methods

MethodParametersReturnsDescription
Constructorpath: String^, mode: String^File^Open file (r/w/a mode)
closeNoneClose file handle
isOpenBool^True if file is open
eofBool^True if at end of file
sizeInteger^Size in bytes

Reading

MethodParametersReturnsDescription
readLineString^Read next line

Writing

MethodParametersReturnsDescription
writeStringtext: String^Integer^Bytes written
writeLinetext: String^Integer^Bytes written (with newline)
flushInteger^Flush buffered data to disk

Examples

Reading a File

xxml
If (IO::File::exists(String::Constructor("config.txt"))) -> {
    Instantiate String^ As <content> = IO::File::readAll(String::Constructor("config.txt"));
    Run Console::printLine(content);
}

Writing a File

xxml
Instantiate IO::File^ As <out> = IO::File::Constructor(
    String::Constructor("output.txt"),
    String::Constructor("w")
);
Run out.writeLine(String::Constructor("Hello, World!"));
Run out.close();

Reading Line by Line

xxml
Instantiate IO::File^ As <file> = IO::File::Constructor(
    String::Constructor("data.txt"),
    String::Constructor("r")
);
While (file.eof().not()) -> {
    Instantiate String^ As <line> = file.readLine();
    Run Console::printLine(line);
}
Run file.close();