注意:最后关闭流的时候,只需要关闭外层的缓冲流,因为会自动帮我们关闭内层的输入/输出流
package test19;import java.io.*;/*** Created By Intellij IDEA** @author Xinrui Yu* @date 2021/12/5 16:03 星期日*/public class Application {public static void main(String[] args) {FileInputStream fileInputStream = null;FileOutputStream fileOutputStream = null;BufferedInputStream bufferedInputStream = null;BufferedOutputStream bufferedOutputStream = null;byte[] buffer = new byte[1024];try{fileInputStream = new FileInputStream("lupin.mp4");fileOutputStream = new FileOutputStream("lupin3.mp4");bufferedInputStream = new BufferedInputStream(fileInputStream);bufferedOutputStream = new BufferedOutputStream(fileOutputStream);while((bufferedInputStream.read(buffer)) != -1){bufferedOutputStream.write(buffer);}}catch (IOException e){e.printStackTrace();}finally {if(bufferedInputStream != null){try {bufferedInputStream.close();} catch (IOException e) {e.printStackTrace();}}if(bufferedOutputStream != null){try {bufferedOutputStream.close();} catch (IOException e) {e.printStackTrace();}}}}}
