private void copydatabase() throws IOException {
//Open your local db as the input stream
InputStream myinput = mycontext.getAssets().open(DB_NAME);// Path to the just created empty db
String outfilename = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myoutput = new FileOutputStream("/data/data/(packagename)/databases /(datbasename).sqlite");
// transfer byte to inputfile to outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myinput.read(buffer))>0)
{
myoutput.write(buffer,0,length);
}
//Close the streams
myoutput.flush();
myoutput.close();
myinput.close();
}
Làm điều này cho cơ sở dữ liệu thứ hai của bạn.
Có vấn đề với cơ sở dữ liệu thứ hai ..? Tại sao bạn không thực hiện các bước tương tự mà bạn đã sử dụng để sao chép tệp đầu tiên ..? – Mudassir
Bạn nên thêm một số thông tin khác như mã không hoạt động và đầu ra của lỗi logcat. Bạn không thể thấy điều gì sai trong mã của mình. – zapl
@Mudassir tôi có thể sử dụng cùng lớp trợ giúp cơ sở dữ liệu cho lần thứ hai không ..? –