Java FileOutputStream Write saveFile(final String filename, final String s1, final String textOut, final String s3)

Here you can find the source of saveFile(final String filename, final String s1, final String textOut, final String s3)

Description

Save the given text out to the given file.

License

Open Source License

Parameter

Parameter Description
filename a parameter
s1 a parameter
textOut a parameter
s3 a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void saveFile(final String filename, final String s1, final String textOut, final String s3)
        throws IOException 

Method Source Code

//package com.java2s;
/*//from   w w w  . j ava2s.  com
 * Copyright (c) 2003 Stephan D. Cote' - All rights reserved.
 * 
 * This program and the accompanying materials are made available under the 
 * terms of the MIT License which accompanies this distribution, and is 
 * available at http://creativecommons.org/licenses/MIT/
 *
 * Contributors:
 *   Stephan D. Cote 
 *      - Initial concept and implementation
 */

import java.io.File;

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

public class Main {
    /**
     * Save the given text out to the given file.
     *
     * @param filename
     * @param s1
     * @param textOut
     * @param s3
     *
     * @throws IOException
     */
    public static void saveFile(final String filename, final String s1, final String textOut, final String s3)
            throws IOException {
        if ((filename != null) && (filename.length() > 0)) {
            final File file = new File(filename);
            file.mkdirs();
        }

        final File file1 = new File(
                String.valueOf((new StringBuffer(String.valueOf(filename))).append(s1).append(s3)));
        System.out.println("write file ".concat(String.valueOf(file1)));

        // Delete it if it exists
        if (file1.exists()) {
            file1.delete();
        }

        final FileOutputStream fileoutputstream = new FileOutputStream(file1);
        fileoutputstream.write(textOut.getBytes());
        fileoutputstream.close();
    }
}

Related

  1. saveFile(File file, String savePath)
  2. saveFile(final byte[] bytes, final File target)
  3. saveFile(final File file, final byte[] dataToSave)
  4. saveFile(final File file, final String contents, final String encoding)
  5. saveFile(final InputStream in, final String path, final String fileName)
  6. saveFile(InputStream is, File file)
  7. saveFile(InputStream is, String destDir, String fileName)
  8. savefile(InputStream source, String destination)
  9. saveFile(InputStream uploadedInputStream, String serverLocation)