Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1

78 | Chapter 4: AIR Mini-Cookbook


that which the operating system is using, which is available
on theFile class asFile.systemCharset:


stream.writeMultiByte( document.getElementById
( "txtNote" ).value, air.File.systemCharset );

Once the text has been written to the file, it is important to
close the file to avoid any corruption or blocking of access
from other applications. Closing a file is accomplished using
theFileStream.close( ) method.


TIP
XML data is already in textual format and, as such, can
be written to disk using these same series of steps. If the
application uses theXMLHttpRequestobject, then a using
themyXml.responseTextproperty alone may be adequate
for most situations.

<html>
<head>

<title>Write Text</title>
<script type="text/javascript" src="AIRAliases.js"></
script>

<script>
function doLoad( )
{
document.getElementById( "btnSave" ).addEventListener
( "click", doSave );
}

function doSave( )
{
var file =
air.File.applicationResourceDirectory.resolve( "note.txt" );
var stream = new air.FileStream( );

stream.open( file, air.FileMode.WRITE );
stream.writeMultiByte( document.getElementById
( "txtNote" ).value, air.File.systemCharset );
stream.close( );
}
</script>
Free download pdf