Convert InputStream into Stream given a Ch

2019-03-24 02:37发布

问题:

I want to convert an InputStream is into a Stream<String> stream given a Charset cs in such a way that stream consists of the lines of is. Furthermore a line of is should not be read immediately but only in case stream needs it.

回答1:

I think you can try:

Stream<String> lines = new BufferedReader(new InputStreamReader(is, cs)).lines();