通过从文件读取的字节数组创建BufferedImage
import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.IOException; /*来自 N o w J a v a . c o m*/ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import javax.imageio.ImageIO; 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); BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream( ballArray)); ImageIO.write(bufferedImage, "png", /** from * 时 代 J a v a - nowjava.com