android - CreateTempFile returns No Such File or Directory in Pictures folder? -
so here code:
string timestamp = new simpledateformat("yyyymmdd_hhmmss").format(new date()); string imagefilename = "jpeg_" + timestamp + "_"; file storagedir = environment.getexternalstoragepublicdirectory(environment.directory_pictures); file image = file.createtempfile( imagefilename, /* prefix */ ".jpg", /* suffix */ storagedir /* directory */ ); however, application intermittently throws error @ file.createtempfile:
java.io.ioexception: open failed: enoent (no such file or directory). from documentation of file:
parameters: prefix prefix temp file name. suffix suffix temp file name. directory location temp file written, or null default location temporary files, taken "java.io.tmpdir" system property. may necessary set property existing, writable directory method work properly. returns: temporary file. throws: illegalargumentexception - if length of prefix less 3. ioexception - if error occurs when writing file. what possibilities of failing writing temporary file? since point external storage , external sd card plugged inside device.
the javadoc getexternalstoragepublicdirectory() states that:
this directory may not yet exist, must make sure exists before using such file.mkdirs().
after that, think should still check see if directory exists.
Comments
Post a Comment