天天看點

下載下傳檔案到本地

public function downLoad(sourceurl:String,targetfile:String):void{

    var loader:URLLoader = new URLLoader();

    loader.dataFormat = URLLoaderDataFormat.BINARY;

    loader.addEventListener(Event.COMPLETE,

     function(e:Event):void

     {

      var airf:File =File.applicationStorageDirectory.resolvePath(targetfile);

      trace(airf.nativePath);

      //trace(airf.url);

      var fs:FileStream = new FileStream();

      fs.open(airf, FileMode.WRITE);

      fs.writeBytes(loader.data);

      fs.close();

      airf.downloaded = true;          

      //打開此下載下傳完成的檔案

      airf.openWithDefaultApplication();

     });

    loader.addEventListener(ProgressEvent.PROGRESS,function(e:ProgressEvent):void{

     trace(e.bytesLoaded/e.bytesTotal+"/"+100);

    });

    var req:URLRequest = new URLRequest(sourceurl);

    loader.load(req);

   }

繼續閱讀