如何从内部存储读取文件内容-Android应用 [英] How do I read the file content from the Internal storage - Android App

查看:111
本文介绍了如何从内部存储读取文件内容-Android应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用Android的新手.已经在位置data/data/myapp/files/hello.txt中创建了一个文件.该文件的内容为"hello".如何读取文件的内容?

I am a newbie working with Android. A file is already created in the location data/data/myapp/files/hello.txt; the contents of this file is "hello". How do I read the file's content?

推荐答案

看看如何在android

Take a look this how to use storages in android http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

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

To read data from internal storage you need your app files folder and read content from here

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应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆