package bytetest;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class CopyPic {
public static void main(String[] args) {
copyPicture();
}
public static void copyPicture() {
FileOutputStream fos = null;
FileInputStream fis = null;
try {
fos = new FileOutputStream("2.jpg");
fis = new FileInputStream("1.jpg");
byte[] buf = new byte[1024];
int len = 0;
while ((len = fis.read(buf)) != -1) {
fos.write(buf, 0, len);
}
} catch (Exception e) {
throw new RuntimeException("复制文件失败");
} finally {
try {
if (fis != null)
fis.close();
} catch (Exception e2) {
throw new RuntimeException("读取关闭失败");
}
try {
if (fos != null)
fos.close();
} catch (Exception e3) {
throw new RuntimeException("写入关闭失败");
}
}
}
}
练习:复制图片文件
最新推荐文章于 2022-04-20 21:13:59 发布