Java UTF8 Encode getBufferedWriter(final File outFile, final String outEncoding)

Here you can find the source of getBufferedWriter(final File outFile, final String outEncoding)

Description

Create BufferedWriter object from specified file and encoding.

License

Open Source License

Parameter

Parameter Description
outFile file to output.
outEncoding file encoding.

Exception

Parameter Description
IOException when file I/O error happened.

Return

BufferedWiter object.

Declaration

public static BufferedWriter getBufferedWriter(final File outFile, final String outEncoding)
        throws IOException 

Method Source Code

//package com.java2s;
/**************************************************************************
 OmegaT - Computer Assisted Translation (CAT) tool
  with fuzzy matching, translation memory, keyword search,
  glossaries, and translation leveraging into updated projects.
    /*from w  ww . j  a  va  2 s. co  m*/
 Copyright (C) 2016 Hiroshi Miura
       Home page: http://www.omegat.org/
       Support center: http://groups.yahoo.com/group/OmegaT/
    
 This file is part of OmegaT.
    
 OmegaT is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
    
 OmegaT is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **************************************************************************/

import java.io.BufferedWriter;
import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStreamWriter;
import java.nio.charset.Charset;

public class Main {
    /**
     * Create BufferedWriter object from specified file and encoding.
     *
     * @param outFile file to output.
     * @param outEncoding file encoding.
     * @return BufferedWiter object.
     * @throws IOException when file I/O error happened.
     */
    public static BufferedWriter getBufferedWriter(final File outFile, final String outEncoding)
            throws IOException {
        OutputStreamWriter osw;
        if (outEncoding == null) {
            osw = new OutputStreamWriter(new FileOutputStream(outFile), Charset.defaultCharset());
        } else {
            osw = new OutputStreamWriter(new FileOutputStream(outFile), outEncoding);
        }
        return new BufferedWriter(osw);
    }
}

Related

  1. encodeUtf8(String string)
  2. encodeUtf8(String target)
  3. encodeUTF8(String text)
  4. encodeUTF8(String text)
  5. encodeUtf8(String url)
  6. getUTF8Bytes(String string)
  7. getUTF8Bytes(String string)
  8. getUTF8Decoder(boolean ignoreEncodingErrors)
  9. getUTF8StringLength(String string)