Here you can find the source of appendStringToFile(String str, String oFileName)
Parameter | Description |
---|---|
str | a string to write to the output file |
oFileName | the output filename |
Parameter | Description |
---|---|
FileNotFoundException | if the file exists but is a directory rather than a regularfile, does not exist but cannot be created, or cannot beopened for any other reason |
IOException | if an I/O error occurs |
public static void appendStringToFile(String str, String oFileName) throws FileNotFoundException, IOException
//package com.java2s; /*/* w w w. ja v a2s . co m*/ * DAITSS Copyright (C) 2007 University of Florida * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.io.IOException; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintWriter; public class Main { /** * Method to append a string (str) to the end of a file (oFileName). If the * output file does not exist, an attempt will be made to create it. * * @param str * a string to write to the output file * @param oFileName * the output filename * @throws FileNotFoundException * if the file exists but is a directory rather than a regular * file, does not exist but cannot be created, or cannot be * opened for any other reason * @throws IOException * if an I/O error occurs */ public static void appendStringToFile(String str, String oFileName) throws FileNotFoundException, IOException { FileOutputStream ostream; PrintWriter pw; ostream = new FileOutputStream(oFileName, true); pw = new PrintWriter(ostream); pw.println(str); pw.close(); ostream.close(); } }