This example mainly implements Android to get the data in the Assets folder and write it to the SD card, which is mainly to read the database in the Assets folder and write it to the SD memory card.
The complete sample code is as follows:
Import Java.io.File;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Java.io.InputStream;
Import Android.content.Context;
/* The database under the Assets folder is written to the SD card * @author Dave * * public class Writetosd {private context;
String FilePath = android.os.Environment.getExternalStorageDirectory () + "/weather";
Public Writetosd {this.context = context;
if (!isexist ()) {write ();
}} private void Write () {InputStream inputstream;
try {InputStream = Context.getresources (). Getassets (). Open ("addressid.db");
File File = new file (FilePath);
if (!file.exists ()) {file.mkdirs ();
} fileoutputstream FileOutputStream = new FileOutputStream (FilePath + "/database.db");
byte[] buffer = new BYTE[512];
int count = 0;
while ((count = inputstream.read (buffer)) > 0) {fileoutputstream.write (buffer, 0, count);
} fileoutputstream.flush ();
Fileoutputstream.close ();
Inputstream.close ();
SYSTEM.OUT.PRINTLN ("Success");
catch (IOException e) {E.printstacktrace ();
} private Boolean isexist () {File File = new file (FilePath + "/database.db");
if (file.exists ()) {return true;
}else{return false; }
}
}