<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
initialize="windowedapplication1_initializeHandler(event)"
>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
//flash.filesystem.*这个库文件为air独有,web程序则不拥有的
import mx.controls.Alert;
import mx.events.FlexEvent;
private function getStudentInfo():void{
/*File.applicationDirectory.nativePath的值是:
C:\Documents and Settings\a\My Documents\Flex Builder 3\readTxtDemo\bin-debug
*/
// Alert.show(File.applicationDirectory.nativePath);
//创建File对象获取文件路径
var file:File = new File(File.applicationDirectory.nativePath + "/student.txt");
var stream:FileStream = new FileStream(); //创建FileStream对象
stream.open(file,FileMode.READ); //使用FileStream对象以只读方式打开File对象
//将文件中的所有信息显示在文本区域中
txtTextAreaID.text = stream.readUTFBytes(stream.bytesAvailable);
stream.close(); //关闭FileStream对象
}
protected function windowedapplication1_initializeHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
Alert.show(File.applicationDirectory.nativePath);
//相当于一个bin目录
}
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
getStudentInfo();
}
protected function exitButton_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
this.close();
//退出程序
}
]]>
</fx:Script>
<mx:Panel title="从文件中读取数据" verticalAlign="middle" horizontalAlign ="center" width="1078" height="90%">
<mx:TextArea id="txtTextAreaID" width="300" height="200" />
<s:Button label="Click me" click="button1_clickHandler(event)" />
<s:Button label="Exit" id="exitButton" click="exitButton_clickHandler(event)" />
</mx:Panel>
</s:WindowedApplication>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
initialize="windowedapplication1_initializeHandler(event)"
>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
//flash.filesystem.*这个库文件为air独有,web程序则不拥有的
import mx.controls.Alert;
import mx.events.FlexEvent;
private function getStudentInfo():void{
/*File.applicationDirectory.nativePath的值是:
C:\Documents and Settings\a\My Documents\Flex Builder 3\readTxtDemo\bin-debug
*/
// Alert.show(File.applicationDirectory.nativePath);
//创建File对象获取文件路径
var file:File = new File(File.applicationDirectory.nativePath + "/student.txt");
var stream:FileStream = new FileStream(); //创建FileStream对象
stream.open(file,FileMode.READ); //使用FileStream对象以只读方式打开File对象
//将文件中的所有信息显示在文本区域中
txtTextAreaID.text = stream.readUTFBytes(stream.bytesAvailable);
stream.close(); //关闭FileStream对象
}
protected function windowedapplication1_initializeHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
Alert.show(File.applicationDirectory.nativePath);
//相当于一个bin目录
}
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
getStudentInfo();
}
protected function exitButton_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
this.close();
//退出程序
}
]]>
</fx:Script>
<mx:Panel title="从文件中读取数据" verticalAlign="middle" horizontalAlign ="center" width="1078" height="90%">
<mx:TextArea id="txtTextAreaID" width="300" height="200" />
<s:Button label="Click me" click="button1_clickHandler(event)" />
<s:Button label="Exit" id="exitButton" click="exitButton_clickHandler(event)" />
</mx:Panel>
</s:WindowedApplication>