Using the newOutputStream() Method with unbuffered writing - Java File Path IO

Java examples for File Path IO:File Operation

Description

Using the newOutputStream() Method with unbuffered writing

Demo Code

import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
  public static void main(String[] args) {

    Path path = Paths.get("C:/folder1/equipment", "test.txt");
    String str = "test";

    byte data[] = str.getBytes();
    try (OutputStream outputStream = Files.newOutputStream(path)) {
      outputStream.write(data);/*from w w  w .j av a 2s.  c  om*/
    } catch (IOException e) {
      System.err.println(e);
    }

  }
}

Result


Related Tutorials