언어 설정

Menu
Sites
Language
write txt file in tizen native app via c

I create a Tizen Native app, and I want to print some log to a text file, that's i can pull the log out from the device for analyzing. I've do the sample code like below, but seems can't open the file, fopen return NULL.

#include "stdio.h"

FILE *fp = fopen("/opt/usr/apps/org.tizen.test/res/rawdata.txt", "w");

Did anyone can help me? I am in a wrong way?

답변 바로가기

Responses

8 댓글
Ilia Ovechkin
Vikram

Hi, 

Thanks! But I am used the Tizen SDK 2.3Rev2, seems there isn't such Tizen:Io:File supported on SDK 2.3 Rev2.

Ilia Ovechkin

I think "/res" folder is read-only. Try to write the file to "/data".

Mark as answer
Alex Dem

Hi,
1) Try to write into /opt/usr/media/
(or in some internal folders like  /opt/usr/media/Others) with http://tizen.org/privilege/mediastorage in manifest
2) or into
/opt/usr/apps/yourAppID/shared/trusted/
Alexey.

Vikram

Hi, not work.

I've tried the "/opt/usr/apps/AppID/data/rawdata.txt" and "/opt/usr/apps/yourAppID/shared/trusted/rawdata.txt". Failed.

By debugging,  the fopen() is ok, it can return the File pointer, also it's ok to call fprintf, fclose. But I can't find the file under such folder "/trusted" and "/data", both in IDE connection explorer and sdb shell. 

sdb shell raise below error while execute command "cd data" or "cd trusted". Strange, I don't know why? 

sh: cd: data: Not a directory

sh: cd: trusted: Not a directory

Also, I've try to "sdb root on", error "Permission denied". 

Vikram

It's ok to write data in to sub-folder of media, such as "/opt/usr/media/Others" or "/opt/usr/media/Documents". But, I don't think it's the best way, because of in some cases I don't want the data be accessed by other apps. 

Any way, my current issue was resolved. Thanks, Alex!!!

Sunwook Bae

Please use path APIs rather than the hard-coded path.

Ex)

https://developer.tizen.org/dev-guide/2.3.0/org.tizen.native.mobile.apireference/group__CAPI__APP__COMMON__MODULE.html

 

- char* app_get_data_path(void)     

Gets the absolute path to the application's data directory which is used to store private data of the application.
An application can read and write its own files in the application's data directory. 

 

- char* app_get_cache_path     (void)     

Gets the absolute path to the application's cache directory which is used to store temporary data of the application.
An application can read and write its own files in the application's cache directory. 

 

Sunwook

Alex Dem

Hi, 
just fyi: I have checked on custom device first and there is 'sdb root on' command is supported but on official is really 'Permission denied'.
In Native example: 'Media Sample application' captured images or recoreded audio/video are saved into /opt/usr/apps/AppID/data/ folder
Alexey.