java复制图片
时间: 2023-08-22 20:09:59 浏览: 41
你可以使用Java的IO流来复制图片。以下是示例代码:
```java
import java.io.*;
public class ImageCopyExample {
public static void main(String[] args) {
File source = new File("source.jpg");
File dest = new File("dest.jpg");
try (InputStream is = new FileInputStream(source);
OutputStream os = new FileOutputStream(dest)) {
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
在上面的代码中,我们使用`FileInputStream`和`FileOutputStream`来读取和写入图片文件。我们创建一个字节数组缓冲区,并使用`read()`和`write()`方法将数据从输入流复制到输出流。最后,我们关闭输入和输出流。