java - 如何在Java中创建具有特定扩展名的文件的InputStream?

标签 java inputstream

我的目录中有很多文件,但我只想读取具有特定扩展名的文件(例如 .txt)。我希望将这些文件添加到同一个 BufferedInputStream 中,以便我可以一次性读取它们。当我在文件末尾调用 read() 时,下一个文件应该开始。

确实感觉应该有一个明显的答案,但我没有找到它。

最佳答案

您可能想看看SequenceInputStream :

A SequenceInputStream represents the logical concatenation of other input streams. It starts out with an ordered collection of input streams and reads from the first one until end of file is reached, whereupon it reads from the second one, and so on, until end of file is reached on the last of the contained input streams.

关于java - 如何在Java中创建具有特定扩展名的文件的InputStream?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22556481/

相关文章:

使用递归的 Java 元音计数器

java - 使用 JUnit 测试函数,其中函数获取用户输入

java - Android连续获取进程输出

java - Java 中 null(Input/Output)Stream API 的用例是什么?

java - NetBeans:如何将 ScrollBar 添加到 JPanel

java - 如何使用寺庙方法或泛型方法或其他方法优化我的代码?现在我必须编写类似的代码三遍

java - 从 InputStream 读取到 byte[] 会抛出 IndexOutOfBoundsException

java - InputStream 读取不返回 -1

java.lang.IllegalArgumentException : 'hello' does not contain an equals sign

java - 带有 json 和图像处理的 asyctask