How to save/read file on different platforms
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的更多相关文章
- Mac修改文件权限:You don’t have permission to save the file
1.从互联网上或者其他途径拿过来的工程代码,往往会报下面的提示: (1)打开文件的时候出现窗口提示You don’t have permission to save the file “project ...
- 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 ...
- Matlab绘图基础——用print函数保存图片(Print figure or save to file)
print(figure_handle,'formats','-rnumber','filename') %将图形保存为png格式,分辨率为number的(默认为72),最好指定的分辨率大一点,否则 ...
- Matlab绘图基础——用print函数批量保存图片到文件(Print figure or save to file)
一.用法解析 1.1. 分辨率-rnumber 1.2. 输出图片的“格式”formats 二.用法示例 2.1. 设置输出图片的“图像纵横比” 2.2. Batch Processing(图片保存 ...
- 关于在使用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" ...
- 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 ...
- Logging - MVC Using Log4net Save to File and Database
第一步:创建Config文件夹和log4net.config 第二步:在log4net.confg黏贴以下配置 <?xml version="1.0" encoding=&q ...
- 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格式的文件, ...
- [JS] save txt file
(function () { var blob = new Blob(['content'], {type: 'text/plain; charset=utf-8'}), blobUrl = URL. ...
随机推荐
- [Android] 修改设备访问权限
在硬件抽象层模块中,我们是调用open函数来打开对应的设备文件的.例如,在2.3.2小节中开发的硬件抽象层模块freg中,函数freg_device_open调用open函数来打开设备文件/dev/f ...
- 【HDOJ】1254 推箱子
来一发搜索.数据量比较小,这么玩儿都能ac.搞个优先队列.先扫描从起点可以到达箱子的上下左右中哪些位置,并针对这些位置进行bfs.所谓推,就是箱子和人同向移动一个单位.bfs的时候注意一些限制条件就好 ...
- 【HDOJ】1285 确定比赛名次
拓扑排序,居然要考虑重边,使用STL实现. #include <iostream> #include <cstdio> #include <cstring> #in ...
- tlplayer,wzplayer支持wince,winphone,windows8 for arm
tlplayer,wzplayer宣布支持wince,winphone,windows8 for arm,支持http,hls,rtmp,rtsp,mms等媒体流协议. 支持加密视频播放. 目前tlp ...
- Android启动时间测试方法
android apk启动时间可以通过下面的命令来完成测试,最终会生成一个mp4的视屏文件,通过播放录制好的视屏来统计app的启动时间精确到ms级别 例如:adb shell screenreco ...
- Android学习之路——简易版微信为例(一)
这是“Android学习之路”系列文章的开篇,可能会让大家有些失望——这篇文章中我们不介绍简易版微信的实现(不过不是标题党哦,我会在后续博文中一步步实现这个应用程序的).这里主要是和广大园友们聊聊一个 ...
- java CopyOnWriteArrayList的使用
除了加锁外,其实还有一种方式可以防止并发修改异常,这就是将读写分离技术(不是数据库上的). 先回顾一下一个常识: 1.JAVA中“=”操作只是将引用和某个对象关联,假如同时有一个线程将引用指向另外一个 ...
- HDU4370 0 or 1 最短路
分析: 1001 (已更新) 显然,题目给的是一个0/1规划模型.解题的关键在于如何看出这个模型的本质.3个条件明显在刻画未知数之间的关系,从图论的角度思考问题,容易得到下面3个结论:1.X12+X ...
- [codevs1554]最佳课题选择
题目描述 Matrix67要在下个月交给老师n篇论文,论文的内容可以从m个课题中选择.由于课题数有限,Matrix67不得不重复选择一些课题.完成不同课题的论文所花的时间不同.具体地说,对于某个课题i ...
- eclipse tomcat内存溢出,加大内存
保存图片失败,请点击这里获得详细信息. 加入 -Xms256M -Xmx512M -XX:PermSize=256m -XX:MaxPermSize=512m