开发者

Android missing file

I'm testing my android app on a real device. My app creates a log file at:

string strFile = "/data/data/com.MYPROJECT/files/mylog.txt"

(I call write, flush, close methods properly and I can actually confirm that the file is indeed created with the following code)

(new File(strFile)).isFile() -> returns true

And

(new File(strFile + "gibberish")).isFile() -> retu开发者_StackOverflow社区rns false

I want to transfer this file to my PC, so I installed a file explorer from Android market. However when I navigate to /data/ folder I see that it is empty.

So where can I find my file?


It is empty because the Android security model is preventing you from reading directories that do not belong to you.

You can access it from your app because your app owns the file and can therefore do anything it needs to with it.

When accessing the directory from the file explorer you installed, the user that the explorer is running as does not have permission to access anything in the /data directory. This is why it appears to be empty. If you tried to read /data from your app, it would appear to be empty too but because you specify the full path, you can access the end file. This will not work with the explorer, because you still are running as a different user on the device.

There are two options:

  1. Implement some sort of export feature to save the file onto the external SD card. This is FAT formatted and does not enforce permissions so you can access any file stored on it
  2. Root your device to get access to every file, including this particular one
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜