注意这里只能资源对象。 (流对象)
什么是资源呢
资源都会实现AouCloseable接口
我们用的InputStream接口继承Closeable继承AutoCloseable
资源都会有一个close方法 。并且资源放到try()小括号里面
用完了 ,会被自动调用其close方法完成 资源的释放操作
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public static void main(String[] args) throws Exception {
InputStream is= new FileInputStream("src/mamat03.txt");
OutputStream ot= new FileOutputStream("src/mamat03Copy.txt");
byte[] buffer =new byte[1024];
while((len=is.read(buffer))!=-1){
ot.write(buffer, 0, len);
System.out.println("复制完成");
