Java FileOutputStream Write saveToFile(String data, File file)

Here you can find the source of saveToFile(String data, File file)

Description

Save to file.

License

Open Source License

Parameter

Parameter Description
data the data
file the file

Exception

Parameter Description
IOException Signals that an I/O exception has occurred.

Declaration

public static void saveToFile(String data, File file) throws IOException 

Method Source Code

//package com.java2s;
/*//w  w  w  . ja  v  a 2 s . c  o  m
 * Metadata Editor
 * @author Jiri Kremser
 * 
 * 
 * 
 * Metadata Editor - Rich internet application for editing metadata.
 * Copyright (C) 2011  Jiri Kremser (kremser@mzk.cz)
 * Moravian Library in Brno
 *
 * 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.File;

import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
    /**
     * Save to file.
     * 
     * @param data
     *        the data
     * @param file
     *        the file
     * @throws IOException
     *         Signals that an I/O exception has occurred.
     */
    public static void saveToFile(String data, File file) throws IOException {
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(file);
            fos.write(data.getBytes());
        } finally {
            if (fos != null)
                fos.close();
        }
    }
}

Related

  1. saveToFile(final String text, final File file)
  2. saveToFile(InputStream in, File dst)
  3. saveToFile(InputStream in, String fileName)
  4. saveToFile(InputStream stream, File file)
  5. saveToFile(String baseName, String extension, byte[] content)
  6. saveToFile(String data, File file)
  7. saveToFile(String fileName, String fileCode, File dir, String fileExtention)
  8. saveToFile(String filePath, InputStream in)
  9. saveToTextFile(String filename, byte[] text)