java使用io流实现图片复制

时间:2021-05-20 21:32:15

 

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;


public class IOTest {

public static void main(String[] args) throws IOException {
//输入流对象
FileInputStream fis = new FileInputStream("C:\\Users\\Administrator\\Pictures\\321196.jpg");

//输出流对象
FileOutputStream fos = new FileOutputStream("copy.jpg");

byte[] b=new byte[1024];
int lent;
while ((lent=fis.read(b))!=-1) {
//写出数据
fos.write(b,0,lent);
}

//关闭资源
fos.close();
fis.close();

}

}