【发布时间】:2017-11-26 12:27:08
【问题描述】:
我已经尝试过这里发布的许多版本,但没有一个有效,所以我自己问。在我的代码中,我有这个公共功能。该文件存在并有一个文本,但该函数不返回任何内容。
我做错了什么,我必须改变什么以及如何改变?
public String lesen(String dateiname) throws IOException {
FileInputStream fin = openFileInput(dateiname); // z.b. "Montag.txt"
int size;
String neuText = null;
while ((size = fin.read()) != -1) {
neuText += Character.toString((char) size);
}
return neuText;
}
【问题讨论】:
-
"文件存在" -- 你怎么知道?
openFileInput()打开internal storage 中的文件,普通用户是看不到的。您是否使用openFileOutput()创建此文件?此外,一次读取一个字符的文件非常很慢,并且有更好的 Java 解决方案可以从InputStream读取文本。