集册 Java实例教程 使用readAllBytes()方法读取小文件

使用readAllBytes()方法读取小文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

726
使用readAllBytes()方法读取小文件

import java.io.IOException;

import java.nio.file.Files;//时 代      J a v a   公   众 号 - nowjava.com 提 供

import java.nio.file.Path;

import java.nio.file.Paths;


public class Main {

  public static void main(String[] args) {

    Path ball_path = Paths.get("C:/folder1/photos", "ball.png");


    try {

      byte[] ballArray = Files.readAllBytes(ball_path);

    } catch (IOException e) {

      System.out.println(e);/**来 自 时代Java公众号 - N o w J a  v a . c o m**/

    }


  }

}