How do I write a file?

I’ve downloaded the file. ( Image Resources )

And I must save the file.
But could not find a way to save the file. ( i want write file to disk )

Please tell me how to save the file, what is it?

Writefile : function( path, fileName ){
cc.log( “wirteFile how. to… T_T” );

},

ReadFile : function( path, fileName ){
cc.log( “ReadFile” );

return cc.FileUtils.getInstance().getByteArrayFromFile( path + fileName );
}

I wrote them in the native code and binding the function to js.

hammer hammer wrote:

I wrote them in the native code and binding the function to js.

hm… like JNI??

bk choi wrote:

hammer hammer wrote:
> I wrote them in the native code and binding the function to js.
>
hm… like JNI??

Yeah. Exactly.

thanks… hammer
i did it!

It took a little longer, but I feel good.
Now only tests left.

and i got other question.

how do i know… the platform type;
I need to know when writing a file.

simple_class.h

#include “cocos2d.h” it’s not working…

bk choi wrote:

and i got other question.
>
>
how do i know… the platform type;
I need to know when writing a file.
>
simple_class.h
>
#include “cocos2d.h” it’s not working…

if you want to include cocos2d.h,
need to write cocos2d path to test.ini file.
For example,you need to add

cocos_headers = -I%(cocosdir)s/cocos2dx/include -I%(cocosdir)s/cocos2dx/platform -I%(cocosdir)s/cocos2dx/platform/android -I../../cocos2dx/platform/ios -I%(cocosdir)s/cocos2dx -I%(cocosdir)s/cocos2dx/kazmath/include
cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT

I am trying that with the following native code but i get errors in the binding:

string path = CCFileUtils::sharedFileUtils()->getWritablePath();
path.append(fileName);
CCLOG (“saveFile, path = %s”, path.c_str());

CCLOG (“this is the reported size: %f”, size);

FILE *fp = fopen(path.c_str(), “wb”);

if (! fp)
{
CCLOG (“can not create file %s”, path.c_str());
return 0;
}

double result = fwrite(&file, size, 1, fp);

if (result == size)
{
CCLOG (“write these bytes %f”, result);
}
else
{
CCLOG (“error in the write of these bytes %f”, result);
}

fclose(fp);
return path;

Can I please have a look at your native code. Error occurs when trying to convert JSvalue to CCArray. The file data is represented like that ln JS.

Thanks much
hammer lava wrote:

I wrote them in the native code and binding the function to js.

i did it… use native code.