简体   繁体   中英

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

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM