How do I convert string into InputStream?

Category: java.io, viewed: 58160 time(s).

Here you'll find how to convert string into InputStream object using ByteArrayInputStream class.

package org.kodejava.example.io;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

public class StringToStream {
    public static void main(String[] args) {
        String text = "Converting String to InputStream Example";
        
        /*
         * Convert String to InputString using ByteArrayInputStream class.
         * This class constructor takes the string byte array which can be
         * done by calling the getBytes() method.
         */
        try {
            InputStream is = new ByteArrayInputStream(text.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
Click here to lend your support to: Kode Java Org and make a donation at www.pledgie.com !

 

Can't find what you are looking for? Join our FORUMS and ask some questions!
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Sponsored Links

Our Friends

Statistics

Locations of visitors to this page
visitor stats