从SD卡传输SQLite数据库

时间:2018-10-11 03:24:38

标签: android database import

我只是SQLite数据库的初学者,我想了解如何从/ sdcard1而不是/ sdcard0存储数据库。我知道我使用Environment.getExternalStorageDirectory OR 时遇到了错误的路径。

数据库助手:

private static class DatabaseHelper extends SQLiteOpenHelper {
        public DatabaseHelper(Context context) {
            super(context,Environment.getExternalStorageDirectory()+ "/sdcard1"+File.separator + dbname,null,dbversion);
            try {
                InputStream inputStream = new FileInputStream("/data/data/com.example.jaysondeguzman.sqliteapp/databases/ContactsDB.db");
                File file = new File("/data/data/com.example.jaysondeguzman.sqliteapp/databases/ContactsDB.db");
                if (!file.exists()) {
                    file.mkdirs();
                }
                OutputStream outputStream = new FileOutputStream(file.getPath() + "/AppName.backup");
                byte[] bytes = new byte[1024];
                int length;
                while ((length = inputStream.read(bytes)) > 0) {
                    outputStream.write(bytes, 0, length);
                }
                outputStream.flush();
                outputStream.close();
                inputStream.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

我从设备文件资源管理器获得的结果

设备文件资源管理器:

enter image description here

0 个答案:

没有答案