View or download Writer.frink in plain text format
/* This class is a simple wrapper around a Java object to demonstrate
writing to files. The only real reason for this class is to provide a
write[] method that always coerces the input value to a string.
Note: As of the 2012-02-06 release, this functionality is implemented as
part of the Frink standard distribution. The syntax is the same, but you
don't need to include this file anymore.
Example usage:
use Writer.frink
a = new Writer["writerout.txt"]
a.write[2]
a.writeln[" monkeys."]
a.close[]
*/
class Writer
{
// A Java FileWriter object.
var fileWriter
// Constructor to create a new writer, opening the specified file at the
// same time. If append is true, this will append to the file.
new[path, append=false] :=
{
fileWriter = newJava["java.io.FileWriter", [path, append]]
}
// Writes the specified value, as a string, to the output.
write[x] := fileWriter.write[toString[x]]
// Writes the specified value, as a string, to the output, followed by
// a carriage return.
writeln[x] := fileWriter.write[toString[x] + "\n"]
// Closes the file.
close[] :=
{
fileWriter.close[]
fileWriter = undef
}
}
View or download Writer.frink in plain text format
This is a program written in the programming language Frink.
For more information, view the Frink
Documentation or see More Sample Frink Programs.
Alan Eliasen was born 18779 days, 0 hours, 18 minutes ago.