Android 读取手机内存实例
2014-10-11 09:57
246 查看
我们的这个小例子主要讲的就是怎么样读取手机内存里的文件,这个在Android开发当中非常重要的一点,这个要是掌握不好的话,我们就没法把数据库里保存的数据给读出来,也就是说我们我们每一次玩游戏的时候,我们的数据库都是最原始的数据,这样就会给我们带来很多的麻烦。如果出现这样的事情,那你的应用就是非常烂的一个应用,会没有人使用的。不多说了,我们来看看代码:
复制到剪贴板Java代码
public static InputStream readInternalFileInputStream(Context context,String fileName){
/**
* 读取手机内存文件
*
*/
try{
FileInputStream fis = context.openFileInput(fileName);
return fis;
}catch(Exception e){
return null;
}
}
public static String readInternalFile(Context context,String fileName){
/**
* 读取手机内存文件
*
*/
try{
byte[] buffer = new byte[512];
int read =0;
StringBuffer stringbuffer = new StringBuffer();
FileInputStream fis = context.openFileInput(fileName);
do{
read = fis.read(buffer);
if(read>0)
stringbuffer.append(new String(buffer, 0, read, "utf-8"));
}while(read!=-1);
fis.close();
return stringbuffer.toString();
}catch(Exception e){
return null;
}
}
复制到剪贴板Java代码
public static InputStream readInternalFileInputStream(Context context,String fileName){
/**
* 读取手机内存文件
*
*/
try{
FileInputStream fis = context.openFileInput(fileName);
return fis;
}catch(Exception e){
return null;
}
}
public static String readInternalFile(Context context,String fileName){
/**
* 读取手机内存文件
*
*/
try{
byte[] buffer = new byte[512];
int read =0;
StringBuffer stringbuffer = new StringBuffer();
FileInputStream fis = context.openFileInput(fileName);
do{
read = fis.read(buffer);
if(read>0)
stringbuffer.append(new String(buffer, 0, read, "utf-8"));
}while(read!=-1);
fis.close();
return stringbuffer.toString();
}catch(Exception e){
return null;
}
}
相关文章推荐
- Android加载大分辨率图片到手机内存中的实例方法
- Android编程实现读取手机联系人、拨号、发送短信及长按菜单操作方法实例小结
- Android手机开发:ImageView使用和从内存读取图片显示
- Android实例demo1之查看手机内存状态、时间数据大小格式化
- 我的Android之旅(十四)---数据存储2---手机内存数据的读取
- android,保存文件到手机内存和读取
- Android ContentProvider查看/读取手机联系人实例
- Android加载大分辨率图片到手机内存中的实例方法
- Android加载大分辨率图片到手机内存中的实例方法
- Android编程实现读取手机联系人、拨号、发送短信及长按菜单操作方法实例小结
- 获取android手机总内存和可用内存的一些方法
- Android 获取手机总内存和可用内存等信息
- Android 获取手机总内存和可用内存等信息
- Android手机剩余内存一直很小
- android 最省内存的方式读取本地资源的图片
- MediaPlayer读取手机内存文件夹权限问题
- Android手机开发:从网络上读取图片
- android Contacts读取手机号码
- android:读取手机相关信息
- [Android 实例教程] Android,谁动了我的内存