FLEX AIR Read and write Android local files

Source: Internet
Author: User

1. Target: Save the byte stream image on the Android local path, such as "/data/mypppd/",

        File = File.documentsDirectory.resolvePath ("/data/mypppd/" +countpoint+ ". jpg");         New FileStream ();        Filestream.open (file, filemode.write);        Filestream.writebytes (Bytes[countpoint]);        Filestream.close ();

2. Target: Read the picture file display from the Android local directory (for example, to display the ad image)

If you read the picture from "/data/mypppd/", do not know in advance that there are several files in the directory, provide a solution to initialize an array, where the length is set to 7, the display of the loop in turn, encountered a non-existent direct jump to the next loop, so that you can display 0-7 pictures in turn any of the case.

A. Read the picture file locally (saved in urlreq and can be accessed via load)

  

  New Array ();   New Array ();    for (Var j:int = 0; J < 7; J + +)  {      = "/data/mypppd/" + (j+1) + ". jpg";               = File.documentsDirectory.resolvePath (path);       New urlrequest (File[j].url);  }

  

B. Display pictures

protectedfunction Myload ():void{IMG1=NewImage; Load=NewLoader; //Error event when a listener file does not existLoad.contentLoaderInfo.addEventListener (Ioerrorevent.io_error, Loaderrorhandler); //if (urlreq[index]! = null)//loading pictures into loadload.load (Urlreq[index]); //global variable index, control picture sequence number, initialize to 0index++; if(Index >= 7) Index= 0; //Picture Mount completion eventLoad.contentLoaderInfo.addEventListener (Event.complete, imgloaded);} //continue calling Myload () when the picture file does not exist, looking for the next onePrivatefunction Loaderrorhandler (event:ioerrorevent):void{trace (event.tostring ()); if(Index >= 7) Index= 0;            Myload ();} //calling a function after loading endsPrivatefunction imgloaded (e:event):void{    //Displays the loaded picture in an image control named pic.Pic.source=load.content; //VisibleImage.visible =true; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.