Java Files read all bytes from a file

Description

Java Files read all bytes from a file

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

      try {//w w w  . ja va 2  s  .  co  m
         byte[] contents;
         contents = Files.readAllBytes(path);
         for (byte b : contents) {
            System.out.print((char) b);
         }
      } catch (IOException e) {
         e.printStackTrace();
      }

   }
}



PreviousNext

Related