Convert InputStream into Streamlt;Stringgt; given a Charset(将 InputStream 转换为 StreamString给定一个字符集)
问题描述
我想将一个 InputStream is
转换成一个 Stream
给定一个 Charset cs
,使得 stream
由 is
的行组成.此外,一行 is
不应立即读取,而应仅在 stream
需要时才读取.
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.
推荐答案
我觉得你可以试试:
Stream<String> lines = new BufferedReader(new InputStreamReader(is, cs)).lines();
这篇关于将 InputStream 转换为 Stream<String>给定一个字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!