存取在SD卡中
来源:互联网 发布:以撒的结合 mac 下载 编辑:程序博客网 时间:2024/05/22 07:51
//读取文件操作test.txtpublic String readFile(String fileName) throws IOException { String res = ""; try {//判断sd卡是否存在 if (Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) { String SDPATH = Environment.getExternalStorageDirectory().getPath() + "//"; File file = new File(SDPATH + "/" + fileName); if (!file.exists()) { file.createNewFile(); res = "亲,有事忙无法接电话,请稍后联系!"; writeFile(fileName, res); } else { //得到资源中的asset数据流 FileInputStream fis = new FileInputStream(file); int length = fis.available(); byte[] buffer = new byte[length]; fis.read(buffer); res = EncodingUtils.getString(buffer, "UTF-8"); fis.close(); } } else Toast.makeText(this, "sd卡不存在,读取失败", Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } return res;}//写文件public void writeFile(String fileName, String write_str) throws IOException { if (Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) { String SDPATH = Environment.getExternalStorageDirectory().getPath() + "//"; File file = new File(SDPATH + "/" + fileName); System.out.println("9999999999999999" + SDPATH + "/" + fileName); FileOutputStream fos = new FileOutputStream(file); byte[] bytes = write_str.getBytes(); fos.write(bytes); fos.close(); Toast.makeText(this, "写入成功", Toast.LENGTH_SHORT).show(); } else Toast.makeText(this, "sd卡不存在,写入失败", Toast.LENGTH_SHORT).show();}
阅读全文
0 0
- 存取在SD卡中
- SD卡存取文件
- Android中SD Card数据存取
- 在Android模拟器中使用SD卡
- 在Android模拟器中使用SD卡
- 在SD卡中创建文件
- 在vmware 中 如何识别 sd 卡
- 如何在SD卡中创建数据库
- 如何在SD卡中创建数据库
- Android在sd卡中读写联系人
- android--在sd卡中创建文件夹
- android在SD卡中创建数据库
- 在Access中存取图片
- 在Struts2 中存取Cookie.
- 在数据库中存取信息
- 我的 Android 之旅(十九)---数据存储--向SD卡中以实体类的方式存取数据
- Android内存和SD卡的数据存取
- ImageView中的图片保存到SD卡;sd卡中图片显示在ImageView中
- linux服务器上传下载文件
- oracle日期类型
- 商品详情,购物车,订单
- webService基本概念
- JAVA常用的排序冒泡和选择
- 存取在SD卡中
- 【原】JS server not recognized, continuing with build...
- JAVA8日期时间的差值计算方法
- iOS开发
- ActiveReports 报表控件V12新特性 -- RPX报表转换为RDL报表
- SpringBoot继承TkMapper通用Mapper
- 二叉搜索树
- ViewPager轮播图引导页布局
- Delphi整理一(基础知识)