文件字节流的输入输出 组合案例
-
使用文件字节流实现文件的复制
-
案例
/* * 使用文件字节流实现文件的复制 * */ public class TestIO { public static void main(String[] args) throws Exception { //创建流 //1.1文件字节输入流 FileInputStream fis = new FileInputStream("f:\\IO\\123.txt"); //1.2文件字节输出流 FileOutputStream fos = new FileOutputStream("f:\\IO\\456.txt"); //一边读,一边写 byte [] buf=new byte[1024]; int count=0; while ((count=fis.read(buf))!=-1){ fos.write(buf,0,count); } //关闭 fis.close(); fos.close(); System.out.println("复制成功"); } }