Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用root在数据/数据中读写文件_Android_Root - Fatal编程技术网

Android 如何使用root在数据/数据中读写文件

Android 如何使用root在数据/数据中读写文件,android,root,Android,Root,现在我正在使用文件检查一些文件,或者用root删除它们。以下是代码: String tempName = null; boolean hasFound = false; File baseDir = new File("data/data/" + pkgName + "/databases"); if (!baseDir.exists() || !baseDir.isDirectory()) { listener.onExecuteFiled();

现在我正在使用
文件
检查一些文件,或者用root删除它们。以下是代码:

String tempName = null;
    boolean hasFound = false;
    File baseDir = new File("data/data/" + pkgName + "/databases");
    if (!baseDir.exists() || !baseDir.isDirectory()) {
        listener.onExecuteFiled();
    } else {
        File[] filelist = baseDir.listFiles();
        for (File file : filelist) {
            if (!file.isDirectory()) {
                tempName = file.getName();
                if (tempName.toLowerCase().contains("wegamedb")) {
                    if (!file.delete()) {
                        listener.onExecuteFiled();
                        return;
                    } else {
                        hasFound = true;
                    }
                }
            }
        }

        if (hasFound) {
            listener.onExecuteSuccess();
        } else {
            listener.onExecuteFiled();
        }
    }
但是
baseDir.listFiles()
returnnull,所以我想知道如何获得root权限来运行这些代码?我可以使用
su
运行shell,但不知道如何对
文件执行相同的操作


谢谢

您错过了来自的
/

File baseDir = new File("data/data/" + pkgName + "/databases");
应该是

File baseDir = new File("/data/data/" + pkgName + "/databases");
如果您有上下文,我将使用
getDatabasePath
(文档),它返回数据库的绝对路径

File file = context.getDatabasePath("DATABASE_NAME");
如果要将所有文件列在
数据库中

File parentFile = context.getDatabasePath("DATABASE_NAME").getParent();
if (parentFile != null) { 
     File[] dbs = parentFile.listFiles();
}

您错过了来自的
/

File baseDir = new File("data/data/" + pkgName + "/databases");
应该是

File baseDir = new File("/data/data/" + pkgName + "/databases");
如果您有上下文,我将使用
getDatabasePath
(文档),它返回数据库的绝对路径

File file = context.getDatabasePath("DATABASE_NAME");
如果要将所有文件列在
数据库中

File parentFile = context.getDatabasePath("DATABASE_NAME").getParent();
if (parentFile != null) { 
     File[] dbs = parentFile.listFiles();
}

您错过了来自的
/

File baseDir = new File("data/data/" + pkgName + "/databases");
应该是

File baseDir = new File("/data/data/" + pkgName + "/databases");
如果您有上下文,我将使用
getDatabasePath
(文档),它返回数据库的绝对路径

File file = context.getDatabasePath("DATABASE_NAME");
如果要将所有文件列在
数据库中

File parentFile = context.getDatabasePath("DATABASE_NAME").getParent();
if (parentFile != null) { 
     File[] dbs = parentFile.listFiles();
}

您错过了来自的
/

File baseDir = new File("data/data/" + pkgName + "/databases");
应该是

File baseDir = new File("/data/data/" + pkgName + "/databases");
如果您有上下文,我将使用
getDatabasePath
(文档),它返回数据库的绝对路径

File file = context.getDatabasePath("DATABASE_NAME");
如果要将所有文件列在
数据库中

File parentFile = context.getDatabasePath("DATABASE_NAME").getParent();
if (parentFile != null) { 
     File[] dbs = parentFile.listFiles();
}

谢谢,我正在删除/data/data中其他包的文件,所以我不能使用上下文来执行此操作。在我添加
/
之后,它也返回null。谁在返回null?listFiles()?是的,我已经解决了它,我为那些目录和文件运行chmod 777 shell,现在listFiles()不会返回null。您是否仅为应用程序运行它?如果是这种情况,您不需要更改PermissionsHanks,我将删除/data/data中的其他包的文件,因此无法使用上下文来执行此操作。在我添加
/
之后,它也返回null。谁在返回null?listFiles()?是的,我已经解决了它,我为那些目录和文件运行chmod 777 shell,现在listFiles()不会返回null。您是否仅为应用程序运行它?如果是这种情况,您不需要更改PermissionsHanks,我将删除/data/data中的其他包的文件,因此无法使用上下文来执行此操作。在我添加
/
之后,它也返回null。谁在返回null?listFiles()?是的,我已经解决了它,我为那些目录和文件运行chmod 777 shell,现在listFiles()不会返回null。您是否仅为应用程序运行它?如果是这种情况,您不需要更改PermissionsHanks,我将删除/data/data中的其他包的文件,因此无法使用上下文来执行此操作。在我添加
/
之后,它也返回null。谁在返回null?listFiles()?是的,我已经解决了它,我为那些目录和文件运行chmod 777 shell,现在listFiles()不会返回null。您是否仅为应用程序运行它?如果是这种情况,则不需要更改权限