Java File Append Text appendToFile(IFile file, String output)

Here you can find the source of appendToFile(IFile file, String output)

Description

append To File

License

Open Source License

Declaration

public static boolean appendToFile(IFile file, String output) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2016 University of York.
 * 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
 * //w ww  . ja v  a2s . co  m
 * Contributors:
 *     Simos Gerasimou - initial API and implementation
 ******************************************************************************/

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.eclipse.core.resources.IFile;

import org.eclipse.core.runtime.CoreException;

public class Main {
    public static boolean appendToFile(IFile file, String output) {
        try {
            if (!file.exists())
                return false;

            InputStream source = new ByteArrayInputStream(output.getBytes());

            file.appendContents(source, IFile.FORCE, null);
            return true;
        } catch (CoreException e) {
            e.printStackTrace();
        }
        return true;
    }
}

Related

  1. appendToFile(File tempFile, String str)
  2. appendToFile(final File file, final String contents)
  3. appendToFile(final String filePath, final String textToAppend)
  4. appendToFile(final String text, final String urlFile)
  5. appendToFile(float[] in, String filename)
  6. appendToFile(List strList, File file)
  7. appendToFile(String baseFilename, String appendingFilename)
  8. appendToFile(String content, File file, String encoding)
  9. appendToFile(String content, String filename)