iphone/android比较学习之──图片、文件、字符串

来源:互联网 发布:java awt源码 编辑:程序博客网 时间:2024/04/29 13:59

1. 显示图片这两个平台都很简单:

iphone中使用UIImage,告诉它文件path就可以了

android中使用ImageView,同样非常简单

2. 读取文件

iphone中一般借助NSBundle的pathForResource/pathForDocuments获取资源文件路径

而android中使用Context.getResources或者Context.getAssets

 

获取文件的内容iphone相对简单可以调用NSString的stringWithContentsOfFile,直接读入字符串,或者调用NSData的dataWithContentsOfFile读取binary。

Android中就相对复杂一点了,代码类似

InputStreamis = getAssets().open("***");

           int size = is.available();

           byte[] buffer = new byte[size];

           is.read(buffer);

           is.close();

          

           String text = new String(byte);