The examples in this article describe the way in which the Android programming read assets All files (traversing each folder) into the SDcard. Share to everyone for your reference, specific as follows:
private void Copyassets (String assetdir, string dir) {string[] files;
try {//Get assets altogether how many files = This.getresources (). Getassets (). List (Assetdir);
catch (IOException E1) {return;
File Mworkingpath = new file (dir);
If the file path does not exist if (!mworkingpath.exists ()) {//Create folder if (!mworkingpath.mkdirs ()) {//folder creation is unsuccessful when called for (int i = 0; i < files.length; i++) {try {//Get the name of each file String FileName = fi
Les[i]; Whether the folder or file if (!filename.contains (".") is judged by the path
{if (0 = assetdir.length ()) {copyassets (filename, dir + filename + "/");
else {copyassets (Assetdir + "/" + filename, dir + "/" + filename + "/");
} continue;
File outfile = new file (Mworkingpath, fileName);
if (outfile.exists ()) Outfile.delete ();
InputStream in = null; if (0!= aSsetdir.length ()) in = Getassets (). Open (Assetdir + "/" + fileName);
else in = Getassets (). open (FileName);
OutputStream out = new FileOutputStream (outfile);
Transfer bytes from to out byte[] buf = new byte[1024];
int Len;
while (len = In.read (buf)) > 0) {out.write (buf, 0, Len);
} in.close ();
Out.close ();
catch (FileNotFoundException e) {e.printstacktrace ();
catch (IOException e) {e.printstacktrace ();
}
}
}
For more information on Android-related content readers can view the site topics: "Android Development Introduction and Advanced Course", "Android Database Operating skills summary" and "Android Control usage Summary"
I hope this article will help you with the Android program.