java - Android - Copy assets to internal storage -


good day!

i have started developing android. in app, need copy items in assets folder internal storage.

i have searched lot on including copies external storage. how copy files 'assets' folder sdcard?

this want achieve: have directory present in internal storage x>y>z. need file copied y , z.

can me out code snippet? don't have idea how go on this.

sorry bad english.

thanks lot.

use

 string out= environment.getexternalstoragedirectory().getabsolutepath() + "/x/y/z/" ;           file outfile = new file(out, filename); 

after editing in ref. link answer.

  private void copyassets() {     assetmanager assetmanager = getassets();     string[] files = null; try {     files = assetmanager.list(""); } catch (ioexception e) {     log.e("tag", "failed asset file list.", e);   }  for(string filename : files) {     inputstream in = null;     outputstream out = null;     try {       in = assetmanager.open(filename);        string outdir = environment.getexternalstoragedirectory().getabsolutepath() + "/x/y/z/" ;         file outfile = new file(outdir, filename);        out = new fileoutputstream(outfile);       copyfile(in, out);       in.close();       in = null;       out.flush();       out.close();         out = null;       } catch(ioexception e) {           log.e("tag", "failed copy asset file: " + filename, e);          }               }      }      private void copyfile(inputstream in, outputstream out) throws ioexception {         byte[] buffer = new byte[1024];       int read;      while((read = in.read(buffer)) != -1){        out.write(buffer, 0, read);      }    } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -