Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.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:打开不可读的目录_Android_File_Shell_Unix_Root - Fatal编程技术网

Android:打开不可读的目录

Android:打开不可读的目录,android,file,shell,unix,root,Android,File,Shell,Unix,Root,有没有一个好方法来获取文件、目录、链接的信息。。。在不可读的目录中 目前,我使用Chainfire的libsuperuser库,它使我的应用程序能够在root/superuser权限下运行像ls-l这样的Shell命令。所以我可以列出目录的内容,比如“/data/data” /directory的示例: drwxr-xr-x root root 1970-08-10 14:44 acct drwxrwx--- system cache

有没有一个好方法来获取文件、目录、链接的信息。。。在不可读的目录中

目前,我使用Chainfire的libsuperuser库,它使我的应用程序能够在root/superuser权限下运行像ls-l这样的Shell命令。所以我可以列出目录的内容,比如“/data/data”

/directory的示例:

drwxr-xr-x root     root              1970-08-10 14:44 acct
drwxrwx--- system   cache             2014-08-06 18:03 cache
-rwxr-x--- root     root       272364 1970-01-01 01:00 charger
dr-x------ root     root              1970-08-10 14:44 config
lrwxrwxrwx root     root              1970-08-10 14:44 d -> /sys/kernel/debug
drwxrwx--x system   system            2014-08-05 20:33 data
-rw-r--r-- root     root          286 1970-01-01 01:00 default.prop
drwxr-xr-x root     root              2014-08-05 20:36 dev
lrwxrwxrwx root     root              1970-08-10 14:44 etc -> /system/etc
and so on...
对于我的根文件管理器项目,我希望将这些信息包装到Java对象中。但问题是“ls-l”的输出很难解析,因为用户可以在文件名中使用空格,可能在不同的android版本上使用不同的“ls”输出。。。。因此,即使我能够制作一个能够读取“ls-l”输出的解析器,它也可能是非常错误和不可靠的

所以现在我想问一下,是否有更好的解决方案来获取文件信息,如unix权限、所有者、组。。。在不可读的目录中


提前感谢

尝试使用正则表达式从每一行提取文件名:

\d{2}:\d{2}\s(.+)$
我假设ls命令的输出总是相同的:

drwxrwx--- system   cache             2014-08-06 18:03 cache
我们有一些文件信息,日期,时间和文件名。因此,您的代码如下所示:

Pattern pattern = Pattern.compile("\\d{2}:\\d{2}\\s(.+)$");

for (String line : lsLines) {
    Matcher matcher = pattern.matcher(line);

    if (matcher.find()) {
        String filename;
        String tempFilename = matcher.group(1);

        if (tempFilename.indexOf(" -> ") > -1) {
            filename = tempFilename.split(" -> ")[1];
        } else {
            filename = tempFilename;
        }

        // Do something with filename
    }
}

ls命令对于不同的细节有不同的选项,但最终可能需要解析输出。您的标题有点误导,尽管根目录通常指目录树的根,即,/,而不是您作为超级用户运行以访问的根。谢谢您的提示。我改了标题。我找不到任何使解析输出更容易的“ls”选项。你能给我一个提示吗?