黑马程序员技术交流社区

标题: 关于文件分割和和合并中的小问题 [打印本页]

作者: 草鱼狂飙    时间: 2014-5-6 17:24
标题: 关于文件分割和和合并中的小问题
这是我的代码
  1. private static void splitFile() throws Exception {
  2.                 // TODO Auto-generated method stub
  3.                 FileInputStream fis = new FileInputStream("d:\\1.mp3");
  4.                 FileOutputStream fos = null;
  5.                 byte[] by = new byte[1204 * 1024];
  6.                 int len;
  7.                 int count = 0;
  8.                 while ((len = fis.read(by)) != -1) {
  9.                         fos = new FileOutputStream("d:\\splitfile" + (count++) + ".part");
  10.                         fos.write(by);//look!here ,here
  11.                         fos.close();
  12.                 }
  13.         }
复制代码

其中的fos.write(by)和老师视频中的代码fos.write(by,0,len)在理论中有什么区别?


作者: 曹冬明    时间: 2014-5-6 17:54
比如数组中你只读到一个字节,数组也就没满,你确把整个数组都写进去了,这就是区别啊
作者: skill20    时间: 2014-5-6 17:56
区别在数组长度。




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2