Save byte array to a file - Java File Path IO

Java examples for File Path IO:File Operation

Description

Save byte array to a file

Demo Code

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 ball_path = Paths.get("C:/folder1/photos", "ball.png");

    try {/*  w w  w. j a  v a 2s.  co m*/
      byte[] ballArray = Files.readAllBytes(ball_path);
      Files.write(ball_path.resolveSibling("bytes_to_ball.png"), ballArray);        
    } catch (IOException e) {
      System.out.println(e);
    }

  }
}

Result


Related Tutorials