/**
 * File Stream
 *
 * Demonstrates how to read from and write to a file stream.
 */

method main ()
{
    // create temp file
    path = System.IO.File.temp_name()
    file = System.IO.FileStream.new(path, "w", "t", "r")

    // write to temp file
    System.Console.write_bytes("Enter write to file text: ")
    text = System.Console.read_line()
    file.write_line(text)
    file.close()

    // read from temp file
    file = System.IO.FileStream.new(path, "r", "e", "r")
    text = file.read_line()
    print("Text read from file: " + text)
    file.close()

    // delete temp file
    System.IO.File.delete(path)
}

try {
    main()
} else {
    print(last_excp())
}