RAV:
私のアンドロイドアプリケーションでは、私はSQLiteデータベースを使用しています。そして私は、データベースファイルをダウンロードするにはアプリ内のオプションを持っている必要があります。
時にはので、私は、ユーザーがファイルをダウンロードし、それを私に送って、私はSQLiteのブラウザを使用して、それを参照しますしますので、そこにデータを表示する必要があります。
なんとかのですか?どのようにそうであれば?
String src = "/data/data/myPackage/databases/Mydb.db";
String dest = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath();
copyFileOrDirectory(src , dest);
public static void copyFileOrDirectory(String srcDir, String dstDir) {
try {
File src = new File(srcDir);
File dst = new File(dstDir, src.getName());
copyFile(src, dst);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void copyFile(File sourceFile, File destFile) throws IOException {
if (!destFile.getParentFile().exists())
destFile.getParentFile().mkdirs();
if (!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
try {
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
destination.transferFrom(source, 0, source.size());
} finally {
if (source != null) {
source.close();
}
if (destination != null) {
destination.close();
}
}
}
ニザー:
通常、SQLiteのデータベースが利用可能である/data/data/your.applications.package/databases/database.db
パス。
だから、あなたはそのパスを使用することができます。しかし、私はあなたが次のようにデータベースのパスを取得することを示唆しています:
File dbFile = getDatabasePath("dbname");
String dbPath = dbFile.getPath();
次に、あなたが望むことをフォルダにこのフォルダからデータベースをコピーすることができます。データベースをコピーすると、Downloads
SQLiteデータベースの「ダウンロード」をシミュレートすることができます。