Java tutorial
//package com.java2s; import java.io.InputStream; import java.nio.charset.Charset; public class Main { public static InputStream toInputStream(CharSequence input) { return toInputStream(input, Charset.defaultCharset()); } public static InputStream toInputStream(CharSequence input, Charset encoding) { return toInputStream(input.toString(), encoding); } public static InputStream toInputStream(String input) { return toInputStream(input, Charset.defaultCharset()); } }