Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1
File API | 81

If this is the target format of the data for the application,
then these methods should be used directly. In the case of
other character sets, the FileStream.readMultiBytes( )
method can be used to specify the target format. Additional
character sets are specified in the form of a string such as
“us-ascii”. There is also a convenience property on the File
object to use the default system character set, File.
systemCharset.


The number of bytes to be read also needs to be specified in
the case of FileStream.readUTFBytes( ) and FileStream.
readMultiBytes( ). This sizing will depend largely on the
requirements of the application. In the cases where reading
the entire file is required, the number of bytes that are avail-
able to be read can be found on the FileStream.
bytesAvailable property:


var data =
stream.readMultiBytes( stream.bytesAvailable,
air.File.systemCharset );

Once the contents of a file have been read, it is important to
close the file. This operation will allow other applications to
access the file:


stream.close( );

Although a demonstrable amount of flexibility has been pro-
vided by Adobe AIR, the actual process in its entirety is con-
siderably concise. This brevity is provided when performing
synchronous data access operations. Synchronous file access
should be reserved for smaller files regardless of reading or
writing character or binary data:


<html>
<head>

<title>Synchronous File Access</title>
<script type="text/javascript" src="AIRAliases.js"></
script>

<script>
var file = null;
var stream = null;
Free download pdf