Prev | Current Page 596 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

Lib.print( err );
}
pos++;
}
stream.close();
}
}
Again, it is important that you close the stream after use, so as to free up valuable resources.
writeBytes
In this circumstance, the same feat can be accomplished more easily using the writeBytes method. If
you know the length of the string you want to output through a stream, writeBytes enables you to
dump the entire string content in one go, without having to perform a loop.
When using writeBytes , it is possible for the buffer containing the data to not be fully output to
the receiving device. In such circumstances, it is advisable to call the flush method, thereby forcing the
buffer to clear and the data to be written to the device.
309
Chapter 11: Performing Server-Side Trickery
class WriteBytes
{
public static function main()
{
var stream = neko.io.File.write( ???example.txt???, false );
var str = ???abcdefghijklmnopqrstuvwxyz???;
try
{
stream.writeBytes( str, 0, str.length );
stream.flush();
}
catch ( err : Dynamic)
{
//neko.Lib.


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