public class RandomAccessDemo6 {
        public static void main(String[] args) throws IOException {
            RandomAccessFile src = new RandomAccessFile("src.AVI", "r");
            RandomAccessFile des = new RandomAccessFile("copy.AVI", "rw");
            byte[] buf = new byte [1024*10];
            int len = -1;
            while ((len = src.read(buf))!=-1){
                            des.write(buf, 0, len);
            }
            src.close();
            des.close();
        }
}

read(byte[] b)方法的作用是从输入流中读取一定数量的字节,并将其存储在缓冲区数组 b 中。以整数形式返回实际读取的字节数。当读取到结尾的时候,没有字节,read()的返回值为-1。因此,当len==-1的时候结束循环。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2021-07-19
相关资源
相似解决方案