数据库名称以 null 开头

database name preceded with null

我们正在尝试将 sqlite 数据库备份到 SD 卡上,该数据库创建并位于模拟器内部存储中。问题是当找到内部存储的路径时,数据库的 return 名称与它被命名为 "PassWord" 我的问题是为什么在 Device File Explore 中数据库名称前面有 null 字样? Android Studio 3.0 Build tools 26.0.2 YES Manifest permissions added example "nullPassWord" 代码备份到下面的 SD 卡。 如果有更好的从内部备份到外部的方法,欢迎提出建议。我们不想使用 adb pull。

    public void onCOPY(View view){

    File sd = ContextCompat.getExternalFilesDirs(this, null)[1];// THIS IS OK
    System.out.println("################ SD "+sd);
    //File dir = getDatabasePath("PassWord");
    //String currentDBPath = dir.getPath();
    // dir.getPath(); RETURNS This /data/user/0/package name/databases/PassWord
    String currentDBPath = "/data/user/0/package name/databases/nullPassWord/";
    System.out.println("################ Current DB Path "+currentDBPath);

    FileChannel source;
    FileChannel destination;

    String backupDBPath = "NewPassWord";

    File currentDB = new File(currentDBPath);
    File backupDB = new File(sd, backupDBPath);

    try {
        source = new FileInputStream(currentDB).getChannel();
        destination = new FileOutputStream(backupDB).getChannel();
        destination.transferFrom(source, 0, source.size());
        source.close();
        destination.close();
        Toast.makeText(this, "DB Exported!", Toast.LENGTH_LONG).show();
    } catch(IOException e) {
        e.printStackTrace();
    }
}

如果您查看 DBHelper Class,您会在定义数据库名称的代码前面看到一些变量。就像 THE_PATH + "PassWord" 我会 post 代码来找到内部存储中数据库的正确路径

 File dir  = getDatabasePath("PassWord").getAbsoluteFile();
    String currentDBPath = dir.getPath();

所以把THE_PATH字去掉,在其他代码中设置路径?