Here you can find the source of getBufferedWriter(String directory, String filename)
Parameter | Description |
---|---|
filename | the name of the file to write to |
the | directory to put the file is in |
public static BufferedWriter getBufferedWriter(String directory, String filename) throws IOException
//package com.java2s; /* This file is part of the Joshua Machine Translation System. * //www. j a v a 2s.c o m * Joshua is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 * of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */ import java.io.*; public class Main { public static final String FILE_ENCODING = "utf8"; /** * Returns a BufferedWriter. Overwrites the file if it exists. * * @param filename the name of the file to write to * @param the directory to put the file is in * @return BufferedReader to read from the given file name * @exception IOException if a stream cannot be created */ public static BufferedWriter getBufferedWriter(String directory, String filename) throws IOException { return getBufferedWriter(directory, filename, false); } /** * Returns a BufferedWriter. Overwrites the file if it exists. * * @param filename the name of the file to write to * @return BufferedReader to read from the given file name * @exception IOException if a stream cannot be created */ public static BufferedWriter getBufferedWriter(String filename) throws IOException { return getBufferedWriter(filename, false); } /** * Returns a BufferedWriter. Can optionally append ot the file if it exists. * * @param filename the name of the file to write to * @param the directory to put the file is in * @param append a flag to determine whether to append to an existing file or overwrite it * @return BufferedReader to read from the given file name * @exception IOException if a stream cannot be created */ public static BufferedWriter getBufferedWriter(String directory, String filename, boolean append) throws IOException { File file = new File(directory, filename); FileOutputStream outputStream = new FileOutputStream(file, append); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, FILE_ENCODING); return new BufferedWriter(outputStreamWriter); } /** * Returns a BufferedWriter. Can optionally append ot the file if it exists. * * @param filename the name of the file to write to * @param append a flag to determine whether to append to an existing file or overwrite it * @return BufferedReader to read from the given file name * @exception IOException if a stream cannot be created */ public static BufferedWriter getBufferedWriter(String filename, boolean append) throws IOException { FileOutputStream outputStream = new FileOutputStream(filename, append); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, FILE_ENCODING); return new BufferedWriter(outputStreamWriter); } }