Easypt

Files, exceptions and extras

1. Files

A computer file is a computer resource for recording data discretely in a computer storage device. Just as words can be written to paper, so can information be written to a computer file.

From Wikipedia

A file must be opened before you can use it. File object may be use to read from it or write to it. Example:

import("file");
auto testFile.=(File());

testFile.open("test.txt");

Let’s write some contents to this file:

import("file");
auto testFile.=(File());

testFile.open("test.txt");

testFile.clear();
testFile.write("alpha beta\ngamma");

And print it to console:

import("file");
auto testFile.=(File());

testFile.open("test.txt");
testFile.clear();

testFile.write("alpha beta\ngamma");

log(testFile.read());
log(testFile.read());
log(testFile.read());

And write and read again:

import("file");
auto testFile.=(File());

testFile.open("test.txt");
testFile.clear();

testFile.write("alpha beta\ngamma");

log(testFile.read());
log(testFile.read());
log(testFile.read());

testFile.write("delta");
log(testFile.read());

Expected output is:

alpha
beta
gamma
alpha

Why did the last block print “alpha” instead of “delta”? It’s time yo answer the question! Dive into language reference:

Hint: read position indicator


TODO: exceptions, tasks and extras