Java Text File Write by Charset writeStringToStream(String string, OutputStream stream, Charset charset)

Here you can find the source of writeStringToStream(String string, OutputStream stream, Charset charset)

Description

Writes given string to given stream, using given charset

License

Open Source License

Declaration

public static void writeStringToStream(String string, OutputStream stream, Charset charset) throws IOException 

Method Source Code

//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();
        }
    }
}

Related

  1. writeString(OutputStream out, String charset, String value)
  2. writeStringToFile(File file, String s, String charset)
  3. writeStringToFile(String fileContent, String filePath, String charset)
  4. writeStringToFile(String filename, String contents, Charset encoding)
  5. writeStringToFile(String fileName, String str, String charset)
  6. writeTextToFile(String textToWrite, String fileName, Charset cs)