Private void copyassets (string assetdir, string DIR ){
String [] files;
Try {
// Obtain multiple files in assets.
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 a folder
If (! Mworkingpath. mkdirs ()){
// Call when the Folder creation is unsuccessful
}
}
For (INT I = 0; I <files. length; I ++ ){
Try {
// Obtain the name of each file
String filename = files [I];
// Determine whether it is a folder or a file based on the path
If (! Filename. Contains (".")){
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 in to out
Byte [] Buf = new byte [1, 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 ();
}
}
}