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. 如何用AndroidStudio导入github项目

    最近一直在研究AndroidStudio,但是总会有这样那样的问题,特别是在github上看到一个很好地开源项目,想clone下来用用,就会出现很多蛋疼的问题,今天摸索着,结合一些大牛们的建议,轻轻松 ...

  2. Oracle MySQL Server 安全漏洞

    漏洞名称: Oracle MySQL Server 安全漏洞 CNNVD编号: CNNVD-201401-317 发布时间: 2014-01-22 更新时间: 2014-01-22 危害等级: 中危  ...

  3. apache开源项目--JMeter

    JMeter是Apache组织的开放源代码项目,它是功能和性能测试的工具,100%的用java实现.

  4. wpa_supplicant 和 802.11g WPA 认证的配置

    # cd /etc/init.d# ln -s net.lo net.eth0 默认的接口名是 wlan0,让它开机时自动 up:cp /etc/init.d/net.lo /etc/init.d/n ...

  5. POJ --- 2918 求解数独

    Tudoku   Description Tom is a master in several mathematical-theoretical disciplines. He recently fo ...

  6. (转)使用pth文件,让python方便的import自己写的模块

    转自:http://www.elias.cn/Python/PythonPath 文章简单易懂,有理有据. 有时候我们正在修改或调试的程序会是一个库,为修改方便,我们可能不大希望把它放到 site-p ...

  7. linux内存分配机制

    这几天在观察apache使用内存情况,所以特意了解了下linux的内存机制,发现一篇写得还不错.转来看看. 一般来说在ps aux中看到的rss就是进程所占用的物理内存.但是如果将所有程序的rss加起 ...

  8. oracle 创建索引

    一.索引简介 1.索引相当于目录 2.索引是通过一组排序后的索引键来取代默认的全表扫描检索方式,从而提高检索效率. 3.索引的创建要适度,多了会影响增删改的效率,少了会影响查询的效率,索引最好创建在取 ...

  9. Android--应用开发1(应用程序框架)

    应用程序的框架,就是所有开发者共同是有和遵循的约定,大家在约定上进行必要的扩展,但程序的主体结构是一致的. Android系统提供给开发者一个框架,我们所有的应用开发就是在这个框架上进行扩展,下来看看 ...

  10. HW2.12

    控制台: import java.util.Scanner; public class Solution { public static void main(String[] args) { Scan ...