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

Posts: 163
Registered: ‎12-06-2012
My Device: Z10, Q10
My Carrier: BlackBerry

Create a writable file in a native app

I can create a file in an cascade app with the help of Qdir::homePath() and QFile . But I don't know how to do that with native c app. I need to create a file in a folder which is writable and save a video file while recording. Thanks.

Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip

Re: Create a writable file in a native app

Using standard fopen(). Docs here https://developer.blackberry.com/native/reference/bb10/com.qnx.doc.neutrino.lib_ref/topic/f/fopen.ht...




This will open for reading and writing, creating the file if necessary.

FILE *fp = fopen("scores.dat", "ab+");
If you want to read it and then write a new version from scratch, then do it as two steps.

FILE *fp = fopen("scores.dat", "rb");
if (fp) {
    read_scores(fp); //do whatever you want with the file 

// Later...

// truncates the file
FILE *fp = fopen("scores.dat", "wb");
if (!fp)
write_scores(fp); //do whatever you want with the file