Java File Write fileWrite(String[] text, File file)

Here you can find the source of fileWrite(String[] text, File file)

Description

Writes an array of String to specified text file.

License

Open Source License

Parameter

Parameter Description
text an array of string to write to the file
file a text file to be written the text to

Return

true, if the text successfuly write to the file.

Declaration

public static boolean fileWrite(String[] text, File file) 

Method Source Code

//package com.java2s;
/*/*from  www .ja v  a  2  s.  c  o  m*/
 * Copyright (c) 2008 Golden T Studios.
 *
 * This program 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 3 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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

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

import java.io.PrintWriter;

public class Main {
    /**
     * Writes an array of String to specified text file.
     * 
     * @param text an array of string to write to the file
     * @param file a text file to be written the text to
     * @return true, if the text successfuly write to the file.
     */
    public static boolean fileWrite(String[] text, File file) {
        try {
            BufferedWriter out = new BufferedWriter(new FileWriter(file));
            PrintWriter writeOut = new PrintWriter(out);

            // writing text to file
            for (int i = 0; i < text.length; i++) {
                writeOut.println(text[i]);
            }

            writeOut.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
}

Related

  1. fileWrite(String filename, byte[] ba)
  2. fileWrite(String fileName, String str)
  3. fileWrite(String filePath, String data)
  4. fileWrite(String filePath, String fileName, String content)
  5. fileWrite(String path, int format, String content, Object bytesObj)
  6. fileWriteOut(InputStream in, String outPath)
  7. fileWriter(int startpt, int letter)
  8. fileWriter(String outfile, String contents, boolean append)
  9. fileWriteString(String filePath, String strWrite, boolean append)