转自:http://blog.csdn.net/ACCP_2008123456/archive/2010/01/19/5213109.aspx import java.awt.Image; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import javax.imageio.ImageIO; import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JPEGImageEncoder; public class ImageCopy { /** * 图片复制 * @param sourceDir 源文件目录 * @param targetDir 目标文件目录 */ public static void copy(String sourceDir,String targetDir) { try { File file=new File(sourceDir); Image image =ImageIO.read(file); int width=image.getWidth(null); int height=image.getHeight(null); BufferedImage imageTag=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB); imageTag.getGraphics().drawImage(image,0,0,width,height,null); FileOutputStream out=new FileOutputStream(targetDir); JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(out); encoder.encode(imageTag); out.close(); }catch (IOException e) { e.printStackTrace(); } } }