android - How to copy programmatically a file to another directory? -


there image file inside directory. how copy image file directory created ? 2 directories on same internal storage of device :)

you can use these functions. first 1 copy whole directory children or single file if pass in file. second 1 usefull files , called each file in first one.

also note need have permissions that

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

functions:

 public static void copyfileordirectory(string srcdir, string dstdir) {          try {             file src = new file(srcdir);             file dst = new file(dstdir, src.getname());              if (src.isdirectory()) {                  string files[] = src.list();                 int fileslength = files.length;                 (int = 0; < fileslength; i++) {                     string src1 = (new file(src, files[i]).getpath());                     string dst1 = dst.getpath();                     copyfileordirectory(src1, dst1);                  }             } else {                 copyfile(src, dst);             }         } catch (exception e) {             e.printstacktrace();         }     }      public static void copyfile(file sourcefile, file destfile) throws ioexception {         if (!destfile.getparentfile().exists())             destfile.getparentfile().mkdirs();          if (!destfile.exists()) {             destfile.createnewfile();         }          filechannel source = null;         filechannel destination = null;          try {             source = new fileinputstream(sourcefile).getchannel();             destination = new fileoutputstream(destfile).getchannel();             destination.transferfrom(source, 0, source.size());         } {             if (source != null) {                 source.close();             }             if (destination != null) {                 destination.close();             }         }     } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -