android - 如何从内部存储中读取文件内容 - Android 应用

标签 android internal

我是一名使用 Android 的新手。已在 data/data/myapp/files/hello.txt 位置创建了一个文件;这个文件的内容是“你好”。如何读取文件内容?

最佳答案

看看这个如何在android中使用存储http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

要从内部存储中读取数据,您需要您的应用文件夹并从此处读取内容

String yourFilePath = context.getFilesDir() + "/" + "hello.txt";
File yourFile = new File( yourFilePath );

你也可以使用这种方法

FileInputStream fis = context.openFileInput("hello.txt");
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader bufferedReader = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
    sb.append(line);
}

关于android - 如何从内部存储中读取文件内容 - Android 应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14768191/

相关文章:

java - 从内部存储器读取数据

c# 程序集, friend 程序集

android - 如何将图片放入应用程序的内存中?

c# - 内部类中的公共(public)和内部成员?

android - 安全异常 : Unable to start service. 用户 0 被限制

android - 为什么Volley DiskBasedCache拼接不直接获取缓存文件名

Android依赖与嵌入在aar中的jar冲突

javascript - 在内部链接中关闭 EventSource 时如何避免使用全局变量?

onConfigurationChanged 的​​ Android 旋转问题

android - 返回到不同的父 Activity