大话企业级android读书笔记(三)
16lz
2021-01-23
android中的数据存储类型包括:内存,普通文件,Shared Preferences,XML和SQLLite等
文件操作:
包括读写
/** * 【文件操作】 */package Iwit.IwitTest;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import android.content.Context;import android.widget.Toast;/** * @author Shine *【文件读,写】 */public class FileOperate{ /** * 【读取文件】 * @param context * @param fileName * @return */ public String ReadText(Context context,String fileName) { FileInputStream fIn = null; InputStreamReader isr = null; char[] inputBuffer = new char[255]; String data = null; try { fIn =context.openFileInput(fileName); isr = new InputStreamReader(fIn); isr.read(inputBuffer); data = new String(inputBuffer); Toast.makeText(context, "read Succeed",Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(context, " not read",Toast.LENGTH_SHORT).show(); } finally { try { isr.close(); fIn.close(); } catch (IOException e) { e.printStackTrace(); } } return data; } /** * 【写入文件】 * @param context * @param fileName * @param data */ public void WriteText(Context context, String fileName,String data) { FileOutputStream fOut = null; OutputStreamWriter osw = null; try{ fOut =context.openFileOutput(fileName, 1); osw = new OutputStreamWriter(fOut); osw.write(data); osw.flush(); Toast.makeText(context, " saved",Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(context, " not saved",Toast.LENGTH_SHORT).show(); } finally { try { osw.close(); fOut.close(); } catch (IOException e) { e.printStackTrace(); } } }}
关于android操作sdcard的细节,详看
http://www.ylmf.net/zhuanti/zt02/2010/1130/12389.html
接下来是共享参数的操作,这个适合于将一些配置信息存储到这个位置上,可以存储小量的数据
http://www.cnblogs.com/over140/archive/2011/01/13/1934301.html
介绍的很详细
接下来是android操作关于sqllite的操作,
http://www.cnblogs.com/TerryBlog/archive/2010/06/12/1757166.html
连示例都有了,可以下来测试
然后是内容提供访问者ContentProvider
主要是用到多个程序之间对外提供一个可访问的接口,通过统一的uri对外提供访问
http://www.cnblogs.com/linzheng/archive/2011/01/22/1942101.html
更多相关文章
- Android使用系统分享文件给微信,QQ指定的用户
- Android文件下载使用Http协议
- 用Javascript判断访问来源操作系统, 设备, 浏览器类型
- ReactNative 命令生成bundle文件
- Android 手机存储文件各种路径
- 修改android studio 默认的so文件检索路径
- Android环境变量作用--命令行操作
- CreateProcess error=2, 系统找不到指定的文件。