这段代码的等价物是什么:
FileReader reader = null;
try
{
reader = new FileReader( file);
return reader.ready();
}
catch( IOException ex)
{
return false;
}
SmbFile
?我试过了:
BufferedReader reader = null;
try
{
SmbFileInputStream fstream = new SmbFileInputStream( file);
reader = new BufferedReader( new InputStreamReader( fstream));
return reader.ready();
}
catch( IOException ex)
{
return false;
}
然后我总是得到"假"结果。
答案 0 :(得分:1)
根据文档显示,无法保证此标记可以确保无法读取,Note that returning false does not guarantee that the next read will block.
您可以尝试这种方式来避免空值,
String line;
while((line = br.readLine()) != null) {
System.out.println(line);
}
您也可以查看此帖子,bufferedreader-not-stating-ready-when-it-should
希望这有帮助