File
File operations with both static utility methods and instance-based operations.
xxml
Language::IOStatic Methods
| Method | Parameters | Returns | Description |
|---|---|---|---|
| exists | path: String^ | Bool^ | True if file exists |
| delete | path: String^ | Bool^ | True if deleted |
| copy | srcPath: String^, dstPath: String^ | Bool^ | True if copied |
| rename | oldPath: String^, newPath: String^ | Bool^ | True if renamed |
| sizeOf | path: String^ | Integer^ | Size in bytes |
| readAll | path: String^ | String^ | Read entire file content |
Instance Methods
| Method | Parameters | Returns | Description |
|---|---|---|---|
| Constructor | path: String^, mode: String^ | File^ | Open file (r/w/a mode) |
| close | — | None | Close file handle |
| isOpen | — | Bool^ | True if file is open |
| eof | — | Bool^ | True if at end of file |
| size | — | Integer^ | Size in bytes |
Reading
| Method | Parameters | Returns | Description |
|---|---|---|---|
| readLine | — | String^ | Read next line |
Writing
| Method | Parameters | Returns | Description |
|---|---|---|---|
| writeString | text: String^ | Integer^ | Bytes written |
| writeLine | text: String^ | Integer^ | Bytes written (with newline) |
| flush | — | Integer^ | 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();