Java tutorial
//package com.java2s; //License from project: Apache License import android.text.TextUtils; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; public class Main { public static void writeStr(OutputStream out, String str) throws IOException { writeStr(out, str, "UTF-8"); } public static void writeStr(OutputStream out, String str, String charset) throws IOException { if (TextUtils.isEmpty(charset)) charset = "UTF-8"; Writer writer = new OutputStreamWriter(out, charset); writer.write(str); writer.flush(); } }