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
|
public static String DB_PATH = "/data/data/com.truc.machin/databases/";
public static String DB_NAME = "le_nom_de_la_base";
public void copyDataBase() throws IOException{
// crée le repertoire
File f=new File(DB_PATH);
f.mkdirs();
//Open your local db as the input stream
InputStream myInput = this.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(outFileName);
//transfer bytes from the inputfile to the 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();
} |
Partager