2016-8-28 zhulinan Flash
在应用所在位置生成文本文件和文件夹,界面如下:
下面是源码:
package { import flash.display.MovieClip; import flash.events.*; import flash.filesystem.File; import flash.filesystem.FileStream; import flash.filesystem.FileMode; public class Main extends MovieClip { public function Main() { addEventListener(Event.ADDED_TO_STAGE, addedHandle); } private function addedHandle(e:Event):void { btnSaveFile.addEventListener(MouseEvent.CLICK, saveFileHandle); btnCreateDir.addEventListener(MouseEvent.CLICK, createDirHandle); } private function saveFileHandle(e:MouseEvent):void { var str:String = File.applicationDirectory.nativePath + "\\elight.txt"; var file:File = new File(str); var fileStream:FileStream = new FileStream(); fileStream.open(file, FileMode.WRITE); var txt:String = txtText.text; txt = txt.replace(/\r/g, "\r\n");//保证记事本下显示换行 var outputString:String = txt; fileStream.writeUTFBytes(outputString); fileStream.close(); } private function createDirHandle(e:MouseEvent):void { var dirName:String = txtDirName.text; if (dirName == "") return; var str:String = File.applicationDirectory.nativePath + "\\" + dirName; var dir:File = new File(str); if (dir.isDirectory) { //文件夹已存在 //dosomething } else { dir.createDirectory(); } } } }