Here you can find the source of writeFile(String contents, File f)
Parameter | Description |
---|---|
contents | the string to write |
f | the file to write |
Parameter | Description |
---|---|
RuntimeException | if something goes wrong |
public static void writeFile(String contents, File f)
//package com.java2s; /******************************************************************************* * ALMA - Atacama Large Millimeter Array * Copyright (c) ESO - European Southern Observatory, 2011 * (in the framework of the ALMA collaboration). * All rights reserved.//from w w w . ja v a2s . c o m * * This library 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.File; import java.io.FileWriter; import java.io.IOException; public class Main { /** * Writes a string to a file. * * @param contents the string to write * @param f the file to write * @throws RuntimeException if something goes wrong */ public static void writeFile(String contents, File f) { FileWriter fw = null; try { fw = new FileWriter(f); fw.write(contents); } catch (IOException e) { throw new RuntimeException( "workdir is " + System.getProperty("user.dir") + ", couldn't write contents to file: " + e); } finally { try { fw.close(); } catch (Exception exc) { } } } }