Search code examples
javastreamfileinputstream

how can you get a content of a folder with a stream in java?


I'm trying to create my own stream, something like a PathContentStream, that gets a path and returns how many files, folders, and sub-folders are in it and what type they are (like avi or txt).

Is there anything in the java streams API that would be useful to implement this?


Solution

  • It is not quite clear what will be an essense of such stream. General answer: no, there is not such streams in java api. But if you will compose the essense of it, you can create your own, which will implement something like:

    public interface InputFileItemStream implements Closeable {
    
         File read();
         void close();
         void reset();
         ...
    }