Here you can find the source of writeStringToStream(String string, OutputStream stream, Charset charset)
public static void writeStringToStream(String string, OutputStream stream, Charset charset) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2007, 2014 Bruno Medeiros and other Contributors. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w ww .java2s .c om*/ * Bruno Medeiros - initial implementation *******************************************************************************/ import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.nio.charset.Charset; public class Main { /** Writes given string to given stream, using given charset */ public static void writeStringToStream(String string, OutputStream stream, Charset charset) throws IOException { OutputStreamWriter osw = new OutputStreamWriter(stream, charset); try { osw.append(string); osw.flush(); } finally { osw.close(); } } }