File Processing
Working with files is a fundamental task. Quartz provides the system.fs module for file system operations.
Reading a File
The simplest way to read an entire file into a string:
import system.io as io;
import system.fs as fs;
try {
let content = fs.read_file("data.txt");
io.out.println("File content:", content);
} catch (e) {
io.out.println("Error reading file:", e.message);
}
Writing to a File
Writing a string to a file (overwrites if it exists):
import system.fs as fs;
fs.write_file("output.txt", "Hello, Quartz!");
Checking if a File Exists
import system.io as io;
import system.fs as fs;
if (fs.exists("config.json")) {
io.out.println("Configuration found.");
} else {
io.out.println("Using default settings.");
}
Listing Directory Contents
import system.io as io;
import system.fs as fs;
let files = fs.list_dir(".");
for (f in files) {
io.out.println("-", f);
}