Java Files create BufferedWriter for Charset to append
import java.io.BufferedWriter; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; public class Main { public static void main(String[] args) { String newName = "demo2s.com"; Path file = Paths.get("Main.java"); try (BufferedWriter writer = Files.newBufferedWriter(file, Charset.defaultCharset(), StandardOpenOption.APPEND)) { writer.newLine();//from w w w . j a v a 2 s.c o m writer.write(newName, 0, newName.length()); } catch (Exception e) { e.printStackTrace(); } } }