android 读取SD卡目录下文件
2013-07-29 10:40
543 查看
假如要读取SD卡-ceshi目录下的haha.txt文件中的内容,代码如下所示:
@Override public void onCreate() { super.onCreate(); readCatalog("haha.txt"); } public void readCatalog(String fileName){ String catalogText = ""; File file = new File(Paths.getDataDirectoryPath() + fileName); try { FileInputStream input = new FileInputStream(file); BufferedInputStream buffer=new BufferedInputStream(input); BufferedReader reader = new BufferedReader(new InputStreamReader(buffer, "utf-8")); String str = reader.readLine(); while (str != null) { catalogText = catalogText + str + "\n"; str = reader.readLine(); } reader.close(); Log.e("读sd卡文件", catalogText); }catch (Exception e) { e.printStackTrace(); } } public static String getDataDirectoryPath() { return getDataDirectory().getPath() + File.separatorChar; } public static File getDataDirectory() { File dir = new File(cardDirectory() + "data"); if (!dir.exists()) dir.mkdirs(); return dir; } public static String cardDirectory() { return Environment.getExternalStorageDirectory().getPath() + "/ceshi/"; }
相关文章推荐
- android 中读取asset目录中文件并写入SD卡以及从SD卡中读取的简介
- Android--SD卡上的创建、读取、写入文件及目录
- Android 读取目录中的文件列表并展示
- Android读取assets目录下文件数据内容
- android在SD卡不同目录下获取文件
- 解决:Android使用自带sqlite开发时,apk中创建的数据库外部的进程是没有权限去读/写的,而且无法如何读取指定目录下的db文件
- 读取Android sd卡的文件
- Android 读取 assets目录下的文件
- Android sd卡中 storage/emulated/0目录下找不到所保存文件的问题
- Android中assets目录和raw目录的区别及其中properties资源文件的读取
- Android:读取assets目录下文件(一)
- Android读取assests目录下文件
- [转载]android读取sd卡文件的工具类
- android读取内存和sd卡中的txt文件
- android--读取sd卡中text文件
- Android:读取assets目录下文件(二)
- Android从文件目录中写入和读取图片
- Android开发实现读取assets目录下db文件的方法示例
- android读取工程根目录下文件内容
- android捕获异常并保存到sd卡文件目录里