Like this:
(像这样:)
InputStream stream = new ByteArrayInputStream(exampleString.getBytes(StandardCharsets.UTF_8));
Note that this assumes that you want an InputStream that is a stream of bytes that represent your original string encoded as UTF-8 .
(请注意,这假设您需要一个InputStream,它是一个字节流,它表示编码为UTF-8的原始字符串。)
For versions of Java less than 7, replace StandardCharsets.UTF_8
with "UTF-8"
.
(对于Java版本少于7的版本,将StandardCharsets.UTF_8
替换为"UTF-8"
。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…