java - 如何检查 SmbFile 中的流是否已准备好读取?

标签 java java-io jcifs

这段代码的等价物是:

    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;
    }

但结果总是“假”。

最佳答案

根据文档,无法保证该标志无法读取,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

希望这有帮助

关于java - 如何检查 SmbFile 中的流是否已准备好读取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45984848/

相关文章:

java - 线程被锁定

java - 意外输出 NULL

java - 对 Java 中的方法调用进行签名和验证

java - 如何将 SmbFile 转换为 File?

java - 如何将 JCIFS 与 apache VFS 结合使用来访问 SMB URL?

java - JCIFS jcifs.smb.SmbException : A device attached to the system is not functioning

java - 如何覆盖子类中列的特征?

java - Linux命令执行后读取输出将陷入无限循环

java - Android 上的 Flutter path_provider 错误,而在 iOS 上运行完美

java - 检测客户端何时与服务器断开连接