2017-02-02 1 views
0

Je suis en train de sauvegarder mon fichier de base de données sur le stockage interne:Android: Copie d'un fichier sur le stockage interne. Fichier introuvable

File fromFile = new File(context.getDatabasePath("database.db").getPath()); 
FileChannel fromFileChannel = new FileInputStream(fromFile).getChannel(); 

File toFile = new File(context.getFilesDir() + "/database.db"); 
if (toFile.getParentFile() != null) 
    toFile.getParentFile().mkdirs(); 
FileChannel toFileChannel = new FileOutputStream(toFile).getChannel(); 

Log.i("LOG",fromFileChannel.transferTo(0, fromFileChannel.size(), toFileChannel)+""); 

fromFileChannel.close(); 
toFileChannel.close(); 

Le journal renvoie « 69632 » sans aucune erreur, il semble que cela a fonctionné.

Le problème est que je ne trouve pas le fichier. Et le dossier/Android/data ne contient pas de dossier avec mon nom de package d'application. Qu'est-ce que je fais mal?

Répondre

1

Utilisez

File toFile = new File(Environment.getExternalStorageDirectory() 
      + File.separator + "Android/data" + File.separator + context.getPackageName() + File.separator + "/database.db"); 

context.getFilesDir() will give you the directory private to your app, so the files in that will not be available to other apps.