`
raymond.chen
  • 浏览: 1418093 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Flex AIR —— 文件读写

阅读更多

一、文件内容

<funds>
  <fund>
    <name>中银中国</name>
    <lot>274</lot>
    <net>1.6612</net>
  </fund>
  <fund>
    <name>广发稳健</name>
    <lot>280.85</lot>
    <net>1.5942</net>
  </fund>
</funds>
 

 

二、源码

private var filePath:String = null;
private var xmlList:XMLList = null;

private function openConfig():void{
	var file:File = new File();
	file.browseForOpen("选择文件", [new FileFilter("*.xml","*.xml")]);
	file.addEventListener(Event.SELECT, onFileSelect);
}

private function onFileSelect(e:Event):void{
	//读文件
	var fs:FileStream = new FileStream();
	fs.open(File(e.target), FileMode.READ);
	var txt:String = fs.readUTFBytes(fs.bytesAvailable);
	fs.close();
	
	filePath = File(e.target).nativePath; //文件路径
	xmlList = new XMLList(txt); //文件内容
	
	//获取节点值
	lot1.text = xmlList.children()[0].lot;
	netValue1.text = xmlList.children()[0].net;
	
	lot2.text = xmlList.children()[1].lot;
	netValue2.text = xmlList.children()[1].net;
}

private function saveConfig():void{
	//设置节点值
	xmlList.children()[0].lot = lot1.text;
	xmlList.children()[0].net = netValue1.text;
	xmlList.children()[1].lot = lot2.text;
	xmlList.children()[1].net = netValue2.text;
	
	//写文件
	var fs:FileStream = new FileStream();
	fs.open(new File(filePath), FileMode.WRITE); 
	fs.writeUTFBytes(xmlList.toXMLString()); 
	fs.close(); 
}
0
0
分享到:
评论
1 楼 lliiqiang 2016-09-27  
怎么直接删除文件夹啊?固定的几个文件可以删除,不固定的呢?需要固定标准。

相关推荐

Global site tag (gtag.js) - Google Analytics