基本上我使用(在groovy
中)以下结构:
InputStream in = new ByteArrayInputStream("one two three four".getBytes());
但是当我打印其内容时:
println(in.text)
我看到空行。为什么这样?以及如何将这些字节保存在我的 InputStream 中?
最佳答案
您的原始代码在 Groovy 控制台中给我一个编译错误:
InputStream in = new ByteArrayInputStream("one two three four".getBytes());
println(in.text)
1 compilation error:
expecting EOF, found 'in' at line: 1, column: 13
in
是 Groovy 中的保留字。将其更改为 inn
一切正常:
InputStream inn = new ByteArrayInputStream("one two three four".getBytes())
println(inn.text)
有了这个输出:
one two three four
关于java - 为什么我的 ByteArrayInputStream 在从任何字符串创建后为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45525240/