加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Air flex 读/写文件

发布时间:2020-12-15 05:14:05 所属栏目:百科 来源:网络整理
导读:? ?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" xmlns:skins="graphite.skins.*" width="800" height="6
?
<?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"
					   xmlns:skins="graphite.skins.*"
					   width="800" height="600">
	<fx:Script>
		<![CDATA[
			import mx.messaging.AbstractConsumer; 
			
			private function init():void{ 
				
			} 
			
			private function onOpen():void 
			{ 
				var file:File = new File(); 
				file.browseForOpen("Select a text file",[new FileFilter("text file","*.txt")]); 
				file.addEventListener(Event.SELECT,onFileSelect); 
			} 
			
			private function onFileSelect(e:Event):void{ 
				var fs:FileStream = new FileStream(); 
				txtPath.text = File(e.target).nativePath; 
				fs.open(File(e.target),FileMode.READ); 
//				txtContent.text = fs.readMultiByte(fs.bytesAvailable,"gb2312"); fs.close();
				txtContent.text = fs.readMultiByte(fs.bytesAvailable,"utf-8"); fs.close(); 
			} 
			
			private function Save():void{ 
				var fs:FileStream = new FileStream(); 
				fs.open(new File(txtPath.text),FileMode.WRITE); 
				fs.writeUTFBytes(txtContent.text); 
				fs.close(); 
			} 
		]]>
	</fx:Script>
	
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	
	<s:TextInput id="txtPath" x="10" y="10" width="321"/> 
	<s:Button id="btnOpen" x="339" y="10" label="Open" click="onOpen()"/> 
	<s:TextArea id="txtContent" x="10" y="40" width="394" height="276"/> 
	<s:Button x="339" y="324" label="Save" click="Save()"/> 
	
</s:WindowedApplication>
?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读