---
title: "java 读取和保存图片"
author: "shenghw"
date: "2014-10-12T11:22:39Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2014-10-12T11:22:39Z"
id: 2128734
url: "https://wuning.iteye.com/blog/2128734"
---

// 读取图片文件
		InputStream in = new FileInputStream( "c:/test.png");
		byte photo = new byte;
		in.read(photo);
		in.close();


		OutputStream out = new FileOutputStream("c:/copy.png");
		out.write(user.getPhoto());
		out.close();

使用到的实体User
/**
 * 实体
 * 
 * @author tyg
 * 
 */
public class User {
	private int id;
	private String name;
	private Integer age;
	private Date birthday; // 生日
	private String desc; // 一大段说明
	private byte photo; // 头像图片

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public byte getPhoto() {
		return photo;
	}

	public void setPhoto(byte photo) {
		this.photo = photo;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return "";
	}

}