一、使用字节流复制图片
public static void main(String[] args) throws IOException {
FileInputStream fileInputStream = new FileInputStream("IMG_2185.PNG");
FileOutputStream fileOutputStream = new FileOutputStream("img.jpg");
byte[] buffer = new byte[1024];
int len;
while((len = fileInputStream.read(buffer)) != -1){
fileOutputStream.write(buffer,0,len);
}
fileInputStream.close();
fileOutputStream.close();
}
二、使用字节流复制音频
public static void main(String[] args) throws IOException {
FileInputStream fileInputStream = new FileInputStream("1.mp3");
FileOutputStream fileOutputStream = new FileOutputStream("2.mp3");
byte[] buffer = new byte[1024];
int len;
while((len = fileInputStream.read(buffer)) != -1){
fileOutputStream.write(buffer,0,len);
}
fileInputStream.close();
fileOutputStream.close();
}
三、使用字节流复制视频
public static void main(String[] args) throws IOException {
FileInputStream fileInputStream = new FileInputStream("lupin.mp4");
FileOutputStream fileOutputStream = new FileOutputStream("lupin2.mp4");
byte[] buffer = new byte[1024];
int len;
while((len = fileInputStream.read(buffer)) != -1){
fileOutputStream.write(buffer,0,len);
}
fileInputStream.close();
fileOutputStream.close();
}