Writing to a simple file - Java File Path IO

Java examples for File Path IO:File Operation

Description

Writing to a simple file

Demo Code

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) throws IOException {
    Path newPath = Paths.get("/home/docs/newUsers.txt");
    byte[] newContents = "Christopher".getBytes();

    Files.write(newPath, newContents, StandardOpenOption.CREATE);
    Files.write(newPath, newContents, StandardOpenOption.APPEND);

  }/*from w  w  w  .j  av  a2 s. c om*/
}

Related Tutorials