A fájlból való olvasáshoz szükséges modul neve TextIO .
A következő példa soronként beolvassa az input.dat tartalmát és a képernyőre írja.
Az f instream típusú lesz, ami a TextIO modulban van definiálva(minden most következő új függvény, típus ... a TextIO modulban van definialva).
| openIn | string -> instream | fájl megnyitása |
| endOfStream | instream -> bool | teszteli hogy a végére értünk-e a fájlnak |
| inputLine | instream-> string | egy sor beolvasása |
A print egy sor kiírására való. Az stdOut nevű outstream típusú szabványos outputra a konzolra ír, de az openOut : string -> outstream fv-el beállíthatunk tetszőleges állományt ( és az stdErr nevű szabványos hibacsatornát) is, amelyre az oputput függvénnyel írhatunk. A fájlba való íráshoz az output nevű függvény használandó.
a flushOut – a mentésre alkalmas függvény. Egy pl. ami az output.txt fájlba helloka-t ir:
A
type inputstream
| val openIn | string -> instream |
| val closeIn | instream -> unit |
| val input | instream -> vector |
| val inputAll | instream -> vector |
| val inputNoBlock | instream -> vector option |
| val input1 | instream -> elem option |
| val inputN | instream * int -> vector |
| val inputLine | instream -> string |
| val endOfStream | instream -> bool |
| val lookahead | instream -> elem option |
type outstream
| val openOut | string -> outstream |
| val openAppend | string -> outstream |
| val closeOut | outstream -> unit |
| val output | outstream * vector -> unit |
| val output1 | outstream * elem -> unit |
| val outputSubstr | outstream * substring -> unit |
| val flushOut | outstream -> unit |
| val stdOut | outstream |
| val stdErr | outstream |
| val print | string -> unit |