Create UTF8 InputStream
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
public class Util{
public static InputStream toUTF8InputStream(String str) {
InputStream is = null;
try {
is = new ByteArrayInputStream(str.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
// UTF-8 should always be supported
throw new AssertionError();
}
return is;
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
IO ByteArrayInputStream:
- Create ByteArrayInputStream from a String
- Create UTF8 InputStream
- Convert to byte array