用安卓手机qq文件收藏在哪里发文件怎样打和怎样收藏

如何在Android系统,通过URL获取JSON数据并保存到apk文件中??
[问题点数:40分]
如何在Android系统,通过URL获取JSON数据并保存到apk文件中??
[问题点数:40分]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2015年8月 移动开发大版内专家分月排行榜第三2014年9月 移动开发大版内专家分月排行榜第三2014年7月 移动开发大版内专家分月排行榜第三
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。[Android进阶]如何使用文件来保存程序中的数据 - Android移动开发技术文章_手机开发 - 红黑联盟
[Android进阶]如何使用文件来保存程序中的数据
在程序中,有很多保存和获取数据的方法,本篇文章,主要介绍使用文件对程序中的数据进行保存和读取的操作
我直接写了一个帮助类,进行文件的写入和读取操作
* 用于在文件中保存程序数据
* @author zhaokaiqiang
public class FileHelper {
private static final String TAG = &FileHelper&;
private Context mC
FileHelper(Context _mContext) {
mContext = _mC
// 在手机本地硬盘中保存信息
public void save(String fileName, String content) {
FileOutputStream fileOutputStream =
fileOutputStream = mContext.openFileOutput(fileName,
Context.MODE_PRIVATE);
fileOutputStream.write(content.getBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fileOutputStream != null) {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
// 读取手机硬盘中保存的文件
public void read(String fileName) {
FileInputStream fileInputStream =
fileInputStream = mContext.openFileInput(fileName);
int len = 0;
byte[] buffer = new byte[1024];
ByteArrayOutputStream byteArrayInputStream = new ByteArrayOutputStream();
while ((len = fileInputStream.read(buffer)) != -1) {
byteArrayInputStream.write(buffer, 0, len);
String string = new String(byteArrayInputStream.toByteArray());
Log.d(TAG, string);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fileInputStream != null) {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
注意:使用写入操作的时候,写入的内容会将上次写入的内容进行覆盖
写入的文件保存在/data/data/package name/files目录下,使用DDMS可以进行查看
如下图所示:
使用DDMS将文件导出,即可查看内容
上面这些是将数据写入到我们的手机自带的存储空间里,如果想写入我们的SDCard,那么应该怎么做呢?
下面的写入到SDCard的操作
// save infomation in the SDCard
public boolean saveToSDCard(String fileName, String content) {
// judge weather the SDCard exits,and can be read and written
if (!Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
FileOutputStream fileOutputStream =
File file = new File(Environment.getExternalStorageDirectory(),
fileName);
fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(content.getBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fileOutputStream != null) {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
下面是读取位于SDCard根目录下文件的操作方法
// read the file in the SDCard
public String readFromSD(String fileName) {
FileInputStream fileInputStream =
File file = new File(Environment.getExternalStorageDirectory(),
fileName);
fileInputStream = new FileInputStream(file);
int len = 0;
byte[] buffer = new byte[1024];
ByteArrayOutputStream byteArrayInputStream = new ByteArrayOutputStream();
while ((len = fileInputStream.read(buffer)) != -1) {
byteArrayInputStream.write(buffer, 0, len);
String string = new String(byteArrayInputStream.toByteArray());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fileInputStream != null) {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();}

我要回帖

更多关于 安卓手机微信收藏夹 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信