You can use standard c functions, such as fopen, fwrite, to save and read file on different platforms. Of cource, you can use other standard functions to operate with a file. The difficulty is the path to save or read a file.

This article modifies the "HelloWorld" example to show you how to save/read file on different platforms.

Now, CCFileUtils::getWriteablePath() returns a writeable path. You can use it to get the writeable path.

1. Run example on different platforms

1.1 Android

  • Copy FileOperation.h and FileOperation.cpp into cocos2d-x/HelloWorld.
  • Invoke FileOperation::saveFile() and FileOperation::readFile() in HelloWorld::init().
  • Modify cocos2d-x/HelloWorld/android/jni/helloworld/Android.mk.
  • Rebuild and run

You will see the log in eclipse like:

Also, you can see the file content:

1.2 iOS

  • Copy FileOperation.h and FileOperation.mm into cocos2d-x/HelloWorld.
  • Invoke FileOperation::saveFile() and FileOperation::readFile() in HelloWorld::init().
  • Add FileOperation.h and FileOperation into project file.
  • Rebuild and run

You will see the log in eclipse like:

Also, you can see the file content:

Please reference to the apple document:
iOS Aplication Programming Guide - File & the File system
CHN version

1.3 Windows

  • Copy FileOperation.h and FileOperation.cpp into cocos2d-x/HelloWorld.
  • Invoke FileOperation::saveFile() and FileOperation::readFile() in HelloWorld::init().
  • Add FileOperation.h and FileOperation into project file.
  • Rebuild and run

You will see the log in eclipse like:

Also, you can see the file content:

2. Summary

This article just gives a guide of how to save/read file on different platforms. It is not the standard method,
just a workable method.

How to save/read file on different platforms的更多相关文章

  1. Mac修改文件权限:You don’t have permission to save the file

    1.从互联网上或者其他途径拿过来的工程代码,往往会报下面的提示: (1)打开文件的时候出现窗口提示You don’t have permission to save the file “project ...

  2. error: exportArchive: You don’t have permission to save the file “HelloWorld.ipa” in the folder “HelloWorld”.

    成功clean环境和生成archive文件之后,最后一步导出ipa包,遇到了权限问题: you don’t have permission to save the file “HelloWorld.i ...

  3. Matlab绘图基础——用print函数保存图片(Print figure or save to file)

    print(figure_handle,'formats','-rnumber','filename')  %将图形保存为png格式,分辨率为number的(默认为72),最好指定的分辨率大一点,否则 ...

  4. Matlab绘图基础——用print函数批量保存图片到文件(Print figure or save to file)

    一.用法解析 1.1. 分辨率-rnumber 1.2.  输出图片的“格式”formats 二.用法示例 2.1. 设置输出图片的“图像纵横比” 2.2. Batch Processing(图片保存 ...

  5. 关于在使用sparksql写程序是报错以及解决方案:org.apache.spark.sql.AnalysisException: Duplicate column(s): "name" found, cannot save to file.

    说明: spark --version : 2.2.0 我有两个json文件,分别是emp和dept: emp内容如下: {"name": "zhangsan" ...

  6. vim - save current file with a new name but keep editing current file

    http://superuser.com/questions/414110/vim-save-a-file-as-a-different-filename-but-keep-w-as-the-curr ...

  7. Logging - MVC Using Log4net Save to File and Database

    第一步:创建Config文件夹和log4net.config 第二步:在log4net.confg黏贴以下配置 <?xml version="1.0" encoding=&q ...

  8. PCL Save VTK File With Texture Coordinates 使用PCL库来保存带纹理坐标的VTK文件

    我之前有一篇博客Convert PLY to VTK Using PCL 1.6.0 or PCL 1.8.0 使用PCL库将PLY格式转为VTK格式展示了如何将PLY格式文件转化为VTK格式的文件, ...

  9. [JS] save txt file

    (function () { var blob = new Blob(['content'], {type: 'text/plain; charset=utf-8'}), blobUrl = URL. ...

随机推荐

  1. Android imageview显示圆形图片

    需要ImageView显示圆形图片做法如下 public static Bitmap toRoundCorner(Bitmap bitmap, float ratio) { System.out.pr ...

  2. [OJ] Wildcard Matching (Hard)

    LintCode 192. Wildcard Matching (Hard) LeetCode 44. Wildcard Matching (Hard) 第二次刷还是被这题虐. 其实就是跪在一个地方, ...

  3. 【Linux】理解setuid()、setgid()和sticky位

    详见: http://blog.csdn.net/m13666368773/article/details/7615125 Linux SETUID机制 (1)进程运行时能够访问哪些资源或文件,不取决 ...

  4. Outlook接收qq的邮件

    1.先去qq邮箱,设置,账户 开启pop3服务,假如之前开启过,最好关闭之后重新开启 最新版本的必须使用邮箱的独立密码才可以收取邮件 (否则就算你之前开通了,也无法用你的qq账号和密码收取邮件的) 2 ...

  5. WCF - Windows Service Hosting

    WCF - Windows Service Hosting The operation of Windows service hosting is a simple one. Given below ...

  6. poi大数据导入解决方法

    This one comes up quite a lot, but often the reason isn't what you might initially think. So, the fi ...

  7. 下拉列表联动显示(Car表) 三级联动

    .Models namespace 下拉列表联动显示_Car表_.Models { public class ProductorBF { private MyDBDataContext _contex ...

  8. BZOJ_1609_[Usaco2008_Feb]_Eating_Together_麻烦的聚餐_(动态规划,LIS)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1609 给出一串由1,2,3组成的数,求最少需要改动多少个数,使其成为不降或不升序列. 分析 法 ...

  9. win7 64位系统 pl/sql 无法解析指定的连接标识符解决办法

    我用的是win764位,装好后,装了pl/sql 和toad,都连不上数据库,报错位“无法解析指定的连接标识符” 解决办法,经过研究发现安装目录有问题.默认会安装在“C:\Program Files ...

  10. jQuery里面的datepicker日期控件默认是显示英文的,如何显示中文或其他语言呢?

    jQuery里面的datepicker日期控件默认是显示英文的,如何让他显示中文或其他呢? [官方的写法]: (1)引入JS文件: <script type="text/javascr ...