Java Files append to a file

Description

Java Files append to a file

import java.io.IOException;
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 path = Paths.get("Main.java");

      try {//  ww w. j  a v a 2 s  .c o m
         byte[] contents = "demo2s.com".getBytes();

         Files.write(path, contents, StandardOpenOption.APPEND);
      } catch (IOException e) {
         e.printStackTrace();
      }

   }
}



PreviousNext

Related