Java – Convert String to InputStream

If you want to convert a String into InputStream, you can use the following piece of code.


public class ConvertStringToInputStream {

	public static void main(String[] args) {
		try {
			// Convert the String into InputStream 
			String eurekaUrl = "";
			InputStream is = new ByteArrayInputStream(eurekaUrl.getBytes("UTF-8"));
			// Use Apache Commons IO to get the content of the InputStream
			System.out.println(IOUtils.toString(is, "UTF-8")); 
		} catch (Exception e) {



Don’t forget to add the commons-io dependency in the pom.xml.

<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">


Done =)


2 thoughts on “Java – Convert String to InputStream”

  1. Hello

    I dont know JAVA language. But any one know how to develop mobile application in java.
    There are many sites which provide java based application for mobile. They are made in java with .jar extension.

    Also is it possible to retrieve all & recently received SMS from mobile inbox & send it to other mobile???

    I want to develop such type of application. So is it possible or not?

    Thanks & Reply


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.