Here you can find the source of writeFile(File file, StringBuffer buffer)
public static void writeFile(File file, StringBuffer buffer) throws IOException
//package com.java2s; /*************************************************************************** * Copyright (c) 2006 Eike Stepper, Fuggerstr. 39, 10777 Berlin, Germany. * 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 * /*from w w w . jav a 2s. c o m*/ * Contributors: * Eike Stepper - initial API and implementation **************************************************************************/ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import java.io.Writer; public class Main { public static void writeFile(File file, StringBuffer buffer) throws IOException { writeFile(file, buffer.toString()); } public static void writeFile(File file, String str) throws IOException { writeFile(file, str.getBytes()); } public static void writeFile(File file, byte[] bytes) throws IOException { OutputStream os = null; try { os = new FileOutputStream(file); os.write(bytes); } finally { close(os); } } /** * No exception <code>InputStream</code> close method. */ public static void close(InputStream is) { if (is != null) { try { is.close(); } catch (Exception ignore) { ignore.printStackTrace(); } } } /** * No exception <code>OutputStream</code> close method. */ public static void close(OutputStream os) { if (os != null) { try { os.close(); } catch (Exception ignore) { ignore.printStackTrace(); } } } /** * No exception <code>java.io.Reader</code> close method. */ public static void close(Reader rd) { if (rd != null) { try { rd.close(); } catch (Exception ignore) { ignore.printStackTrace(); } } } /** * No exception <code>java.io.Writer</code> close method. */ public static void close(Writer wr) { if (wr != null) { try { wr.close(); } catch (Exception ignore) { ignore.printStackTrace(); } } } }