Here you can find the source of saveFile(File file, String text, boolean append)
public static void saveFile(File file, String text, boolean append) throws IOException
//package com.java2s; /*//w w w.j a v a2 s.c om * Copyright 2012 Red Hat, Inc. and/or its affiliates. * * Licensed under the Eclipse Public License version 1.0, available at * http://www.eclipse.org/legal/epl-v10.html */ import java.io.File; import java.io.FileWriter; import java.io.IOException; public class Main { public static void saveFile(File file, String text, boolean append) throws IOException { if (file.isDirectory()) { throw new IOException(file + ": Is a directory"); } else if (file.isFile()) { FileWriter fileWriter; // append text at the end of the file if (append) fileWriter = new FileWriter(file, true); // overwrite the file else fileWriter = new FileWriter(file, false); fileWriter.write(text); fileWriter.flush(); fileWriter.close(); } else { // create a new file and write to it FileWriter fileWriter = new FileWriter(file, false); fileWriter.write(text); fileWriter.flush(); fileWriter.close(); } } }