简体   繁体   中英

Error in DB SQLite Android

I have a problem coping my DB to my APK...

I found this code, and im using it but that sends me the error:

Toast.makeText(getApplicationContext(), "Archivo no encontrado.", Toast.LENGTH_SHORT).show();//FILE DOESNT FOUND

This is the code...

private void copiarBaseDatos() {
    String ruta = "/data/data/com.example.bbay/databases/";
    String archivo = "DBBay";
    File archivoDB = new File(ruta + archivo);
    if (!archivoDB.exists()) 
    {
        try 
        {
            InputStream IS = getApplicationContext().getAssets().open(archivo);
            OutputStream OS = new FileOutputStream(archivoDB);
            byte[] buffer = new byte[1024];
            int length = 0;
            while ((length = IS.read(buffer))>0)
            {
                OS.write(buffer, 0, length);
            }
            OS.flush();
            OS.close();
            IS.close();
        } 
        catch(FileNotFoundException e) 
        {
            Toast.makeText(getApplicationContext(), "Archivo no encontrado.", Toast.LENGTH_SHORT).show();//FILE DOESNT FOUND
        } 
        catch (IOException e) {
            Toast.makeText(getApplicationContext(), "Error al copiar la Base de Datos.", Toast.LENGTH_SHORT).show();
        }
    }
}

any help is wellcome, thanks.

尝试

this.getApplicationContext

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM