图片属于字节流,使用InputStream和OutputStream。
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class CopyImage { public static void main(String[] args) throws IOException { File inFile = new File("F:\\1.jpg"); File outFile = new File("D:\\1.jpg"); FileInputStream in = new FileInputStream(inFile); FileOutputStream out = new FileOutputStream(outFile); byte[] buf = new byte[1024]; int length = 0; //边读边写 while ((length = in.read(buf)) != -1) { out.write(buf, 0, length); } out.close(); in.close(); } }
时间: 2024-11-05 19:00:29