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_MARS学习笔记_S01原始版_006_ListView
一.代码1.xml(1)main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayo ...
- WPF 3D 小小小小引擎 - ·WPF 3D变换应用
原文:WPF 3D 小小小小引擎 - ·WPF 3D变换应用 WPF可以提供的3D模型使我们可以轻松地创建3D实体,虽然目前来看还很有一些性能上的问题,不过对于一些简单的3D应用应该是可取的,毕竟其开 ...
- 防止服务器宕机时MySQL数据丢失的几种方案
这篇文章主要介绍了防止服务器宕机时MySQL数据丢失的几种方案,结合实践介绍了Replication和Monitor以及Failover这三个项目的应用,需要的朋友可以参考下. 对于多数应用来说,My ...
- MySQL information_schema表查询导致内存暴涨
case:下面的一条sql语句,导致mysql实例内存暴涨: select * from tables where table_name not in(select table_name from p ...
- 结构体dtype_t
/* SQL data type struct */ typedef struct dtype_struct dtype_t; struct dtype_struct{ unsigned mtype: ...
- 【转】自定义垂直的UISlider
原文网址:http://www.cocoachina.com/bbs/read.php?tid=96282 怎样自定义垂直的UISlider? UISlider弄成垂直的代码就是:slider.tra ...
- M-矩阵
实方阵 $A$ 称为 $M$-矩阵, 是指 $A=cI-B$, $B\geq 0$, $c\geq \rho(B)$. 这里, $M$ 据说是暗指 Minkowski.
- Java笔记(十二)……类中各部分加载顺序及存放位置问题
什么时候会加载类 使用到类中的内容时加载,三种情况: 创建对象:new StaticDemo(); 使用类中的静态成员:StaticCode.num = 9; StaticCode.getNum() ...
- bzoj3998 [TJOI2015]弦论(SAM)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3998 [题意] 询问排名第k的子串是谁,0代表相同子串不同位置算作相同,1代表相同子串 ...
- HW4.4
public class Solution { public static void main(String[] args) { final double KILOMETERS_PER_MILE = ...