Here you can find the source of appendFile(String fileContents, File toFile)
Parameter | Description |
---|---|
fileContents | contents which are appended to the file. |
toFile | a file to append contents. |
Parameter | Description |
---|---|
IOException | ,exception while writing contents into a file |
public static void appendFile(String fileContents, File toFile) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2007, 2008 Symbian Software Limited 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:/*from w ww . j ava 2 s . c o m*/ * Bala Torati (Symbian) - Initial API and implementation * Mark Espiritu (VastSystems) - bug 215283 *******************************************************************************/ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; public class Main { /** * This method is to append the given contents into a file. * * @param fileContents contents which are appended to the file. * @param toFile a file to append contents. * @throws IOException, * exception while writing contents into a file * * @since 4.0 */ public static void appendFile(String fileContents, File toFile) throws IOException { RandomAccessFile raf = null; if (!toFile.exists()) { throw new FileNotFoundException(" The specified destination file does not exists "); //$NON-NLS-1$ } else { try { raf = new RandomAccessFile(toFile, "rw"); //$NON-NLS-1$ raf.skipBytes((int) raf.length()); raf.writeBytes(fileContents); } finally { if (raf != null) { raf.close(); } } } } }