Here you can find the source of fileWrite(String[] text, File file)
Parameter | Description |
---|---|
text | an array of string to write to the file |
file | a text file to be written the text to |
public static boolean fileWrite(String[] text, File file)
//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; } } }