Here you can find the source of write(File file, String data, boolean append)
public static void write(File file, String data, boolean append) throws IOException
//package com.java2s; /* Copyright ? 2015 Gerald Rosenberg. * Use of this source code is governed by a BSD-style * license that can be found in the License.md file. *//*from w w w. j ava 2 s . c o m*/ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.OpenOption; import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.HashSet; import java.util.Set; public class Main { public static void write(File file, String data, boolean append) throws IOException { Set<OpenOption> options = new HashSet<OpenOption>(); options.add(StandardOpenOption.CREATE); options.add(StandardOpenOption.WRITE); if (append) { options.add(StandardOpenOption.APPEND); } else { options.add(StandardOpenOption.TRUNCATE_EXISTING); } write(file, data, options.toArray(new OpenOption[options.size()])); } private static void write(File file, String data, OpenOption... options) throws IOException { Path path = file.toPath(); Files.write(path, data.getBytes(), options); } }