zoukankan      html  css  js  c++  java
  • Flex读取txt文件中的内容(三)

    Flex读取txt文件中的内容


    1、设计源码

    LoadTxt.mxml:

    <?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"
    					   width="100%" height="100%" creationComplete="initCompleteHandler()">
    	<fx:Script>
    		<![CDATA[
    			import mx.controls.Alert;
    			import mx.events.FlexEvent;
    
    			/*初始化函数*/
    			protected function initCompleteHandler():void
    			{
    				//创建File对象获取文件路径
    				var file:File = new File(File.applicationDirectory.nativePath+"/phone.txt");
    				//创建FileStream对象
    				var stream:FileStream = new FileStream();
    				//使用FileStream对象以只读方式打开File对象
    				stream.open(file,FileMode.READ);
    				//将文件中的所有信息显示在文本区域中
    				var strs:String = stream.readUTFBytes(stream.bytesAvailable);
    				txtTextAreaID.text = strs;
    				
    				//关闭FileStream对象
    				stream.close();
    				
    				var temp:String = "";
    				for(var ix:int =0;ix < strs.length;ix++)
    				{
    					var charCode:Number = strs.charCodeAt(ix);
    					if(charCode >= 48 && charCode <= 57)
    					{
    						temp += strs.charAt(ix);
    					}
    					else if(charCode == 10)
    					{
    						//,替换空格
    						temp += ",";
    					}
    				}
    				var strArr:Array = temp.split(",");
    				for each(var str:String in strArr)
    				{
    					trace(str);
    				}
    				Alert.show(strArr.length + "","数组长度");
    			}
    
    		]]>
    	</fx:Script>
    	<fx:Declarations>
    		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
    	</fx:Declarations>
    	
    	<mx:Panel title="从文件中读取数据" width="1200" height="680">
    		<mx:TextArea id="txtTextAreaID" width="100%" height="100%"/>
    	</mx:Panel>
    </s:WindowedApplication>
    

    2、设计结果

    (1)初始化



    (2)单击确定后



    (3)控制台


  • 相关阅读:
    优先队列
    Problem W UVA 662 二十三 Fast Food
    UVA 607 二十二 Scheduling Lectures
    UVA 590 二十一 Always on the run
    UVA 442 二十 Matrix Chain Multiplication
    UVA 437 十九 The Tower of Babylon
    UVA 10254 十八 The Priest Mathematician
    UVA 10453 十七 Make Palindrome
    UVA 10163 十六 Storage Keepers
    UVA 1252 十五 Twenty Questions
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13315137.html
Copyright © 2011-2022 走看看