Java FileOutputStream Write saveToFile(final String text, final File file)

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

Description

save To File

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 eBay Inc. 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:/*w  w w  . ja v  a  2  s. co m*/
 *     eBay Inc. - initial API and implementation
 *******************************************************************************/

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

public class Main {
    public static final String ENCODING = "UTF-8";

    public static void saveToFile(final String text, final File file) throws IOException {
        final FileOutputStream os = new FileOutputStream(file);
        try {
            os.write(text.getBytes(ENCODING));
            os.flush();
        } finally {
            os.close();
        }
    }
}

Related

  1. saveToDisk(String contents, String filename)
  2. saveToEml(Message mail, File emlFile)
  3. saveToFile(byte[] data, String filename)
  4. saveToFile(File file, byte[] buffer)
  5. saveToFile(final String file, final byte[] data, final boolean overwrite)
  6. saveToFile(InputStream in, File dst)
  7. saveToFile(InputStream in, String fileName)
  8. saveToFile(InputStream stream, File file)
  9. saveToFile(String baseName, String extension, byte[] content)