How to convert a String[] array to InputStream in Java

I have a String[] array and I need to convert it to InputStream .

I've seen Byte[] -> InputStream and String -> InputStream , but not this. Any tips?


You can construct a merged String with some separator and then to byte[] and then to ByteArrayInputStream .

Here's a way to convert a String to InputStream in Java.


Have a look at the following link: http://www.mkyong.com/java/how-to-convert-string-to-inputstream-in-java/

However, the difference in the code is that you should concatenate all the strings together in one string before converting.

 String concatenatedString = ... convert your array

        // convert String into InputStream
        InputStream is = new ByteArrayInputStream(str.getBytes());

        // read it with BufferedReader
        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }

        br.close();
链接地址: http://www.djcxy.com/p/78464.html

上一篇: 让扫描器在java中读取一个字符串

下一篇: 如何在Java中将String []数组转换为InputStream