I am downloading a file from a URL using AsyncTask. The file is saved and I can see it on my SD card. In my application, I want to open this file after downloading it, but there is the following error:
java.io.FileNotFoundException: /mnt/sdcard/XML/zurt.xml: open failed: ENOENT (No such file or directory)
Do I have to wait a certain time between downloading and opening a file? What is the problem?
I have both permissions:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" > </uses-permission> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" > </uses-permission>
My AsyncTask:
These codes try to open the saved file:
private ArrayList<Datapoint> parseXML() { try { Log.w("AndroidParseXMLActivity", "Start"); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); File file = new File(Environment.getExternalStorageDirectory()+ FileSeperator+"XML" +FileSeperator+ Name + FileExtension); XMLContentHandler myXMLHandler = new XMLContentHandler(); xr.setContentHandler(myXMLHandler); xr.parse(new InputSource(new InputStreamReader(new FileInputStream(file)))); itemsList = myXMLHandler.getItemsList(); Log.w("AndroidParseXMLActivity", "Done"); } catch (Exception e) { Log.w("AndroidParseXMLActivity",e ); } return itemsList ;
}
source share