Android/Java File.mkdirs() in external storage not working -


first off, want specify have

<uses-permission android:name="android.permission.write_external_storage" /> 

specified in manifest, , check environment.media_mounted.

the strange thing this, in opinion, returns true, doesn't create directories.

public static void downloadfiles(arraylist<filelist> list) {      (filelist file: list) {         try {             // download directory             file download = new file(downloaddirpatch.getcanonicalpath(), file.getpath());              // downloaddirpatch defined follows in different class:             //             // private static string updatedir = "cognitionupdate";             // private static file sdcard = environment.getexternalstoragedirectory();             // final public static file downloaddir = new file(sdcard, updatedir);             // final public static file downloaddirpatch = new file(downloaddir, "patch");             // final public static file downloaddirfile = new file(downloaddir, "file");              if (dev_mode)                 log.i(tag, "download file: " + download.getcanonicalpath());              // check if directory exists or not             if (!download.exists())                 // directory doesn't exist, attempt create                 if (download.mkdirs()) {                     // directory created                     download.download(new url(file.geturl() + file.getpatch()), file.getpath(), file.getname(), true);                 } else {                     throw new externalstoragesetupfailedexception("download sub-directories not created");                 }             else {                 // directory exists                 download.download(new url(file.geturl() + file.getpatch()), file.getpath(), file.getname(), true);             }         } catch (filenotfoundexception fnfe) {             fnfe.printstacktrace();         } catch (ioexception ie) {             ie.printstacktrace();         } catch (externalstoragesetupfailedexception essfe) {             essfe.printstacktrace();         }     } } 

"if (download.mkdirs())" returns true, when app goes download file throws a

filenotfoundexception: open failed: enoent (no such file or directory) 

exception, , when check directory afterwards on phone, doesn't exist.

earlier in program, app sets parent download directory, , works fine using file.mkdir(), file.mkdirs() doesn't seem working me.

your question not give detail filenotfoundexception. check path triggers this. forget think path is, log or run through debugger see is.

as per directories not created correctly, verify (with eyes) path think is. see logging download.getcanonicalpath, check in logs is.

finally, download.download saving stuff think does? before call preparing , verifying directory using download, not using download when call download.download, it's impossible tell.

btw, don't repeat yourself, can rewrite without repeating download.download line:

        if (!download.exists())             if (!download.mkdirs()) {                 throw new externalstoragesetupfailedexception("download sub-directories not created");             }         }         download.download(new url(file.geturl() + file.getpatch()), file.getpath(), file.getname(), true); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -