我的目录中有很多文件,但我只想读取具有特定扩展名的文件(例如 .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/