android - Add res/raw folder content file (video) to external SD folder -


the idea want put content/s of res/raw folder external sd folder named "myfolder".

my way used uri access video file in res/raw , used fileoutputstream , not working, way possible?

*i have permissions needed read , write external sd, , placed correclty in manifest.

code below, thank you

string extstoragedirectory = environment.getexternalstoragedirectory().tostring();     string basepath = extstoragedirectory + "/myfolder/";     uri uripath=uri.parse             ("android.resource://com.example.videoplayer.videoplayer/" + r.raw.video1);  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_videoplayer);      file videodir= new file(basepath);     if (!videodir.exists()) {         videodir.mkdirs();         toast.maketext(getapplicationcontext(),                 "directory created!", toast.length_long)                 .show();     }else{         toast.maketext(getapplicationcontext(),                 "directory exists!", toast.length_long)                 .show();     }     file file = new file (basepath, "android.resource://com.example.videoplayer.videoplayer/" + r.raw.video1); //im not sure if code reaches video1 file      if (file.exists ()) file.delete ();     try {         fileoutputstream out = new fileoutputstream(file); //this line doesnt work         toast.maketext(getapplicationcontext(),                 "file created!", toast.length_long)                 .show();         out.flush();         out.close();      } catch (exception e) {         e.printstacktrace();         toast.maketext(getapplicationcontext(),                 "file error!", toast.length_long)                 .show();     } } 

private void copyfileordir(string path) { assetmanager assetmanager = this.getassets(); string assets[] = null; try {     assets = assetmanager.list(path);     if (assets.length == 0) {         copyfile(path);     } else {         string fullpath = "/data/data/" + this.getpackagename() + "/" + path;         file dir = new file(fullpath);         if (!dir.exists())             dir.mkdir();         (int = 0; < assets.length; ++i) {             copyfileordir(path + "/" + assets[i]);         }     } } catch (ioexception ex) {     log.e("tag", "i/o exception", ex);  } }  private void copyfile(string filename) { assetmanager assetmanager = this.getassets();  inputstream in = null; outputstream out = null; try {     in = assetmanager.open(filename);     string newfilename = "/data/data/" + this.getpackagename() + "/" + filename;     out = new fileoutputstream(newfilename);      byte[] buffer = new byte[1024];     int read;     while ((read = in.read(buffer)) != -1) {         out.write(buffer, 0, read);     }     in.close();     in = null;     out.flush();     out.close();     out = null; } catch (exception e) {     log.e("tag", e.getmessage()); }  } 

to use above code call function copyfileordir("myfolder");


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo