java IO 复制文件

    科技2022-07-11  81

    java IO 复制文件

    学习记录 复制文件a.txt

    import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; public class CopyTest { public static void main(String[] args) throws Exception { //输出字节流,读文件 FileInputStream fis = new FileInputStream("a.txt"); //输入字节流,写入文件 FileOutputStream fos = new FileOutputStream("b.txt"); //缓冲 byte[] buffer = new byte[1024]; int len; while((len=fis.read(buffer))!=-1){ fos.write(buffer,0,len); } //释放资源 fis.close(); fos.close(); } }
    Processed: 0.012, SQL: 8