sdcard之写入和读取
来源:互联网 发布:嘉唯枕头怎么样 知乎 编辑:程序博客网 时间:2024/06/05 16:59
private void writeDataFromInternet(String str) { try { File file = new File(Environment.getExternalStorageDirectory(), "cache.txt"); if (!file.exists()){ file.createNewFile(); } OutputStream fos = new FileOutputStream(file); fos.write(str.getBytes()); Log.i("=====", "writeDataFromInternet: "+str); fos.close(); } catch (IOException e) { e.printStackTrace(); } } //判断sdcard卡是否挂载 public boolean isSdCardExist() { Log.e("=====", "isSdCardExist: "); return Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED); }//读取//读取sdcard文件 private void readFileFromSdcard(){ try { File file = new File(Environment.getExternalStorageDirectory(), "cache.txt"); FileInputStream is = new FileInputStream(file); byte[] b = new byte[is.available()]; is.read(b); String result = new String(b); System.out.println("读取成功:"+result); Gson gson=new Gson(); ComicBean comicBean = gson.fromJson(result, ComicBean.class); Log.e("=====", "readFileFromSdcard: "+comicBean.getData().getComics().get(0).getTitle()); GridLayoutManager manager = new GridLayoutManager(getContext(), 3); rv.setLayoutManager(manager); MyRecyclerViewAdapter adapter = new MyRecyclerViewAdapter(getContext()); adapter.setData(comicBean.getData().getComics()); rv.setAdapter(adapter); adapter.notifyDataSetChanged(); } catch (Exception e) { e.printStackTrace(); } }
阅读全文
0 0
- sdcard之写入和读取
- 通用类_读取和写入SDCard
- 将文件写入到sdcard 并读取
- Android往sdcard写入读取数据
- LitJSON之JSON读取和写入
- Python之文件读取和写入
- 写入SDCard
- SdCard读取文件和音乐
- Android之内置和外置sdcard路径显示并且写入数据
- xml读取和写入
- 文本文件读取和写入
- ListView 读取和写入
- plist写入和读取
- CSV读取和写入
- vrml 读取和写入
- 文件读取和写入
- 文件读取和写入
- 文件读取和写入
- 织梦模板下载:政府供销社类部门织梦网站模板
- const关键字
- 面试总结
- 在写php时遇到的PHPExcel相关问题记录(含excel与mysql交互代码)
- Linux 下maven私服搭建二(上传第三方jar)
- sdcard之写入和读取
- Android中关于APP的版本更新问题
- Thinking in java中创建线程任务Task的基本方法
- 开发一个业务逻辑复杂的系统,应该怎么样设计才能使项目的扩展性更好
- RedHat 7 安装Docker 1.12.6
- Pycharm如何添加第三方库和插件
- 织梦cms模板与wordpress模板比较哪个好?
- webform 本地化资源实现中英双语系统
- Git远程协作开发通用操作