我一直在尝试从资产文件夹复制一个sqlite数据库文件,以便创建一个sqlite数据库并在我的程序中使用它,这是代码:-
首先 SqliteOpenHelperClass
public class DBHandler extends SQLiteOpenHelper {
protected static final String DATABASE_NAME_PRODUCTION = "productionComments.db";
public DBHandler(Context context, String name, SQLiteDatabase.CursorFactory factory,
int version) {
super(context, name, factory, DATABASE_VERSION);
}
//copy database from assets folder (.sqlite) file to an empty database
public void copyDataBase() throws IOException{
//Open your local db as the input stream
InputStream myInput = context.getAssets().open("prod.db");
// Path to the just created empty db
String outFileName = "/data/data/com.qarun.qpcbeta/databases/"+DATABASE_NAME_PRODUCTION;
//Open the empty db as the output stream
OutputStream …Run Code Online (Sandbox Code Playgroud)