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. 131. Palindrome Partitioning

    题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...

  2. Dojo Widget系统(转)

    Dojo 里所有的小部件(Widget)都会直接或间接的继承 dijit._Widget / dijit._WidgetBase dijit._Widget 是 dojo 1.6 和 1.6之前的版本 ...

  3. Bex64

    http://speedupcomputercleaner.com/windows-7-error-bex64.php   How To Fix Windows 7 Error Bex64 ? Wha ...

  4. android webview 访问https页面 SslError 处理

    在Android中,WebView可以用来加载http和https网页到本地应用的控件.但是在默认情况下,通过loadUrl(String url)方法,可以顺利loadUrl(“http://www ...

  5. STL总结之functor

    STL中仿函数是重要的组成部分.所谓的仿函数就是通过重载括号运算符实现的, 如下: STL库中都是泛型仿函数如小于操作: STL中定义了许多有用的操作,如less(小于), less_equal(小于 ...

  6. bzoj 3172 [Tjoi2013]单词(fail树,DP)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3172 [题意] 题目的意思是这样的,给若干个单词,求每个单词在这一堆单词中的出现次数. ...

  7. Tsinsen A1516. fx 数位dp

    题目: http://www.tsinsen.com/A1516 A1516. fx 时间限制:2.0s   内存限制:256.0MB    总提交次数:164   AC次数:72   平均分:51. ...

  8. linux中cron用法

    http://blog.chinaunix.net/uid-677314-id-83387.html

  9. Scala IDE for Eclipse的下载、安装和WordCount的初步使用(本地模式和集群模式)

    包括: Scala IDE for Eclipse的下载  Scala IDE for Eclipse的安装 本地模式或集群模式 我们知道,对于开发而言,IDE是有很多个选择的版本.如我们大部分人经常 ...

  10. YII访问数据库

    YII访问数据库 CDbConnection: 一个抽象数据库连接 CDbCommand: SQL statement CDbDataReader: 匹配结果集的一行记录 CDbTransaction ...