Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Super Contributor
lyon819
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
My Carrier: TT
Accepted Solution

how to save data into txt file.

Does anyone know why txt file is empty without any content??

                         FILE* f= fopen("/shared/documents/save.dat", "w");
                           if(f==NULL){
                             fprintf(stderr,"Cannot create output.txt\n");
                             _exit(1);
                           }
                           fprintf(f,"Hello World");

 

File is created, but the txt file is empt without "Hello World".

-Fight with BB10
Please use plain text.
Super Contributor
lyon819
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
My Carrier: TT

Re: how to save data into txt file.

Ha ha solved.

 

fclose(f);

-Fight with BB10
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: how to save data into txt file.

Yes, without closing it, data isn't necessarily written out to the filesystem.

You should also be able to do fflush(f) to force the data to be written out, allowing you to continue writing more data afterwards. It's somewhat unusual to want to do this but handy for log files, among other things.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.