Java:将字符串列表作为InputStream访问 [英] Java: accessing a List of Strings as an InputStream

查看:279
本文介绍了Java:将字符串列表作为InputStream访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以包装String列表?我想做类似的事情:

Is there any way InputStream wrapping a list of UTF-8 String? I'd like to do something like:

InputStream in = new XyzInputStream( List<String> lines )

推荐答案

您可以将所有行连接在一起以创建字符串,然后使用String#getBytes将其转换为字节数组并将其传递到

You can concatenate all the lines together to create a String then convert it to a byte array using String#getBytes and pass it into ByteArrayInputStream. However this is not the most efficient way of doing it.

这篇关于Java:将字符串列表作为InputStream访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆