Folder for temporary files creation in android, Why does /data/local/tmp doesn't work for me?

巧了我就是萌 提交于 2019-12-09 02:02:10

问题


I am trying to create a temporary file in /data/local/tmp directory. The path is correct and I have added permission WRITE_EXTERNAL_PERMISSION also. But still I get an error from native code saying that file can't be created.

The code is as below.

File *file = fopen("mytxt.txt", "/data/local/tmp/");

The return value file always contains a null value and no file is created. Is there anything else needed to do?

Is there any other temporary folder that i can use for this purpose in android?

Thanks for any help that i can get.


回答1:


The second parameter passed to fopen() is incorrect. That parameter should be an opening mode, not a directory path. See the man page of fopen.




回答2:


You can't access the /data folder unless your phone is rooted.

I'm not sure about the NDK, but there's a method in the SDK to get the cache directory

http://developer.android.com/reference/android/content/Context.html#getCacheDir%28%29

There's probably the same thing in the NDK.



来源:https://stackoverflow.com/questions/4864875/folder-for-temporary-files-creation-in-android-why-does-data-local-tmp-doesnt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!