问题描述
我写了一个单元一个基本的记事本应用程序,在大学。我创建了主类与EDITTEXT我保存为字符串textOutput。
I am writing a basic notepad app for a unit at uni. I have created the main class with an editText which I save as string textOutput.
我已经使用的Android开发者网站上的以下code字符串保存到一个文件中:
I have used the following code from the android developers website to save the string to a file:
FileOutputStream fos = openFileOutput(textOutput, Context.MODE_PRIVATE);
fos.write(textOutput.getBytes());
fos.close();
不过,他们说看你使用了以下几个阶段:
However, they say to read you use the following stages:
要读取内部存储的文件:
呼叫openFileInput(),并通过读取文件的名字吧。这将返回一个FileInputStream。 阅读与从文件中读取的字节()。 然后关闭与关闭()流。
Call openFileInput() and pass it the name of the file to read. This returns a FileInputStream. Read bytes from the file with read(). Then close the stream with close().
这到底这是否意味着,谁给我落实到我的应用程序?
What the hell does this mean, and who to I implement it into my app?
请帮忙。
推荐答案
如何使用的一个例子的 openFileInput 的:
An example of how to use openFileInput:
FileInputStream in = openFileInput("filename.txt");
InputStreamReader inputStreamReader = new InputStreamReader(in);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder sb = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
sb.append(line);
}
这篇关于安卓:从文件中读取(Openfileinput)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!