Prev | Current Page 594 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


getContent is very simple. It accepts the path to the file you wish to query and returns a string
containing the contents of the file:
class GetContent
{
public static function main()
{
var str = neko.io.File.getContent( ???example.txt??? );
neko.Lib.print( str );
}
}
As you can see, this certainly makes for lighter work, and is perfect for reading configuration files and
the like.
Writing Data to a Stream
There are two ways to attain a stream for writing, because there are two ways to write data. One way
involves creating a new file using a given filename and writing content to it, while the other involves
opening an existing file and appending content to the end of its existing data. Both are simple, and in
many ways, not very different to reading from a stream. As there is so little difference to their usages,
this chapter only details examples using one of the methods, though you can choose to use whichever
method suits the task at hand.
To create a new file for writing, you would use:
var stream = neko.


Pages:
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606