Here you can find the source of writeFile(String fileName, String[] contents)
public static boolean writeFile(String fileName, String[] contents)
//package com.java2s; /* Copyright (C) 2009 SRI International */*from w w w .j a v a 2 s .com*/ * This program 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 2 * of the License, or (at your option) any later version. * * This program 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import java.io.*; public class Main { /** * description writes the array of strings into the file name speecified */ public static boolean writeFile(String fileName, String[] contents) { BufferedWriter bufWriter = null; String line; boolean success = true; if (null == contents) { return false; } try { bufWriter = new BufferedWriter(new FileWriter(fileName)); for (int i = 0; i < contents.length; i++) { line = contents[i]; bufWriter.write(line); } } catch (IOException ioex) { success = false; System.out.println( "Exception " + ioex.getMessage() + " returned while attempting to write file " + fileName); } finally { try { if (null != bufWriter) { bufWriter.close(); } } catch (IOException ioex2) { success = false; System.out.println( "Exception " + ioex2.getMessage() + " returned while attempting to close file " + fileName); } } return success; } }