1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| private static final int VERSION_BDD = 1;
private static final String NOM_BDD = "bdd.db";
private static String DB_PATH = "/data/data/monpackageadequate/databases/";
private final Context myContext;
private SQLiteDatabase myDataBase;
public MaDataBase(Context context) {
super(context, NOM_BDD, null, VERSION_BDD);
this.myContext = context;
}
public MaDataBase(Context context, String name, CursorFactory factory, int version) {
super(context, name, factory, version);
this.myContext = context;
}
public void createDataBase() throws IOException{
File f=new File(DB_PATH);
f.mkdirs();
InputStream assetsDB = myContext.getAssets().open(NOM_BDD);
String outFileName = DB_PATH + NOM_BDD;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = assetsDB.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
assetsDB.close();
} |