我有一个文件,我们称之为 text.txt。它包含几行文本。我正在尝试用我的代码读入它,以便我可以使用我的代码对其进行编辑,不幸的是,每当我尝试阅读它时,它只会返回 null,并且根本不加载代码。没有错误信息或任何东西。
一个示例是其中包含以下内容的文件:
a
b
c
d
e
f
加载时,它会加载以下内容:
a
b
c
d
null
这对我来说毫无意义,因为如果它正在进入 while 循环,它不应该退出!谁能帮帮我?
try
{
File theFile = new File(docName);
if (theFile.exists() && theFile.canRead())
{
BufferedReader docFile;
docFile = new BufferedReader(
new FileReader(f));
String aLine = docFile.readLine();
while (aLine != null)
{
aLine = docFile.readLine();
doc.add( aLine );
}
docFile.close();
}