Android FileOutputStream location save file(Android FileOutputStream 位置保存文件)
问题描述
我有一个应用程序将用户输入的数据保存到文件(内部存储)中,并在启动时加载此文件并显示内容.我想知道:在哪里可以找到我的文件 (data.txt
)?此外,如果我在加载文件时输入Hello",然后输入World",我会在同一行看到HelloWorld",但我希望将Hello"和World"打印在两个不同的行上.
I have an app that saves into a file (internal storage) data input by the user and at startup it loads this file and shows the contents. I would like to know: where can I find my file (data.txt
)?
In addition, if I input "Hello" and then "World" when I load the file, I see "HelloWorld" in the same line but I want "Hello" and "World" printed on two different lines.
保存文件:
用于加载文件:
谢谢.
[更新]
我在每次输入后都插入了 ":
I've inserted " " after every input:
但是当我打印我的文件时,它们总是在同一行.
But when I print my file, they are always on the same line.
推荐答案
在哪里可以找到我的文件 (data.txt)?
Where can I find my file (data.txt)?
您可以使用 YourActivity.this.getFilesDir().getAbsolutePath()
找到由 openFileOutput
创建的目录的路径.
You can find the path of the directory, which is created by openFileOutput
, by using YourActivity.this.getFilesDir().getAbsolutePath()
.
但我想将Hello"和World"打印在两行不同的行中.
But I want "Hello" and "World" printed in two different lines.
在文件中写入一个单词后使用line.separator
,例如:
Use line.separator
after writing a word in a file, for example:
或者你也可以使用 replaceAll
将字符串分成多行:
Or you can also use replaceAll
to break String into multiple lines:
这篇关于Android FileOutputStream 位置保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!