Read byte by byte with InputStream unbuffered stream - Java File Path IO

Java examples for File Path IO:File Stream

Description

Read byte by byte with InputStream unbuffered stream

Demo Code

import java.io.IOException;
import java.io.InputStream;
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");

    int n;/*from   w  ww  .  ja v a  2s  .c  o m*/
    byte[] in_buffer = new byte[1024];
    try (InputStream in = Files.newInputStream(path)) {
      while ((n = in.read(in_buffer)) != -1) {
        System.out.println(new String(in_buffer));
      }
    } catch (IOException e) {
      System.err.println(e);
    }

  }
}

Result


Related Tutorials