如何在Android上使用文件描述符获取文件路径? [英] How to get file path using file descriptor on Android?

查看:282
本文介绍了如何在Android上使用文件描述符获取文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用由 getFileDescriptor(). 我该怎么办?

I need to get file absolute path using file descriptor which was returned by getFileDescriptor(). How can i do it?

推荐答案

在Linux内核下运行的系统上(这将是所有当前 Android实现),每个文件描述符在/proc/[processid]/fd是指向文件描述符目标的符号链接-不仅适用于常规文件,还适用于许多其他可能的目标,例如管道和套接字.

On a system running under a Linux kernel, which would be all current Android implementations, each file descriptor will have an entry in /proc/[processid]/fd which is a symbolic link to the target of the file descriptor - not only for regular files, but also for many other possible targets such as pipes and sockets.

这是在Android设备上运行的cat > /mnt/sdcard/foo进程的部分示例

Here's a partial example for a cat > /mnt/sdcard/foo process running on an android device

$ ls -l /proc/3528/fd
lrwx------ shell    shell             2013-06-06 10:31 0 -> /dev/pts/1
l-wx------ shell    shell             2013-06-06 10:31 1 -> /mnt/sdcard/foo
lrwx------ shell    shell             2013-06-06 10:31 2 -> /dev/pts/1
lrwx------ shell    shell             2013-06-06 10:31 6 -> socket:[188850]

在Java中阅读符号链接留给读者练习".

Reading symbolic links in Java "is left as an exercise to the reader".

在台式机Linux上,有一个lsof工具可在所有进程中浏览这些目录并转储打开文件的列表-但是,在Android上,按应用程序用户ID的使用不会太有用限制这种拖钓.但是,您仍然可以查找应用程序本身所属的fd或在同一用户ID下运行的任何其他进程.

On a desktop linux, there's the lsof tool which trolls through these directories for all processes and dumps out a list of open files - however, that would not be too useful on Android where the usage of per-app userids would restrict such trolling. But you can still lookup the fd's belonging to your app itself, or any other process running under the same userid.

这篇关于如何在Android上使用文件描述符获取文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆