简体   繁体   中英

Check if LOCAL file exists (Flex 4 Mobile)

I'm currently using this code:

        private function getFile(file:String):void
        {
            var openFile:URLRequest = new URLRequest("file:///sdcard/GNs/"+file);
            try {navigateToURL(openFile);}
            catch(e:Error)
            {
                var download:URLRequest = new URLRequest("http://"+file);
                new DLAlert().open(this, true);
            }
        }

to find a file, and give a popup for an optional download if it does not exist. The problem is, the errors returned when trying the navigateToURL(...) command are handled by the web/file browser, and not by the app. Is there a way to look for it without trying to open it?

Use this:

var myfile:File = new File("/sdcard/GNs/"+file);
if (myfile.exists)
{
   // your code here
}
else
{
   // your code here
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM