问题
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