Java Write String to File writeFile(File file, String content)

Here you can find the source of writeFile(File file, String content)

Description

write File

License

Open Source License

Declaration

public static void writeFile(File file, String content) throws IOException 

Method Source Code

//package com.java2s;
/*/*from   www.  j  av  a2 s.  c  om*/
 * Copyright (c) 2005 IBM Corporation and others.
 * 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
 *
 * Contributors:
 *   IBM - initial API and implementation
 *
 * $Id: BuildUtil.java,v 1.3 2007/02/22 08:40:26 asobolev Exp $
 */

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

import java.io.FileWriter;
import java.io.IOException;

public class Main {
    public static void writeFile(File file, String content) throws IOException {
        if (!file.getParentFile().isDirectory()) {
            file.getParentFile().mkdirs();
        }

        BufferedWriter out = null;
        try {
            out = new BufferedWriter(new FileWriter(file));
            out.write(content);
        } finally {
            if (out != null) {
                out.close();
            }
        }
    }
}

Related

  1. writeFile(File f, String s)
  2. writeFile(File f, String str)
  3. writeFile(File f, String str)
  4. writeFile(File f, String text)
  5. writeFile(File file, Iterable lines)
  6. writeFile(File file, String content)
  7. writeFile(File file, String content)
  8. writeFile(File file, String content)
  9. writeFile(File file, String content)