thinkinterview » interview questions » Java
« Previous

Java Interview Questions

next »
question Code to convert String into InputStream
Answer Description: 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();
        }
    }
}

Next Queston » Code to get an exception stack trace message...
Code to get an exception stack trace messa... View full queston »

Posted in: Java(30) |