Java Files create OutputStream to append
import java.io.InputStream; import java.io.OutputStream; 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) { Path file = Paths.get("Main.java"); Path newFile = Paths.get("MainUsers.txt"); try (InputStream in = Files.newInputStream(file); OutputStream out = Files.newOutputStream(newFile, StandardOpenOption.CREATE, StandardOpenOption.APPEND)) { int data = in.read(); while (data != -1) { out.write(data);//from ww w . j av a2 s .c o m data = in.read(); } } catch (Exception e) { e.printStackTrace(); } } }