我有一个文件,我们称之为text.txt。它包含几行文字。我试图用我的代码读取它,以便我可以使用我的代码进行编辑,不幸的是,每当我尝试阅读代码时,它都会返回null,并且根本不会加载代码。没有错误信息或任何东西。Java从文件读取问题
一个例子是在它下面的一个文件:
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();
}
更不用说,他在添加aLine到doc *之前检查它是否为空。 – johusman 2011-02-26 20:12:10