最近正好遇到了使用RandomAccessFile做断点下载的情况,被一个问题坑了好多次

本来的代码:

RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rwd");
FileOutputStream fos = new FileOutputStream(file);

这样两句联在一起,有问题!!!
FileOutputStream fos = new FileOutputStream(file);这句会把f.getFilePointer=0以及 f.length()=0。。。导致
RandomAccessFile  seek没起到作用,而且会让后面生成一个错误的文件!!!

要根据情况,在不同的分支里分别new 这两个对象!

相关文章:

  • 2021-12-05
  • 2021-09-23
  • 2021-05-02
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
猜你喜欢
  • 2021-06-18
  • 2021-05-05
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2022-02-04
  • 2021-05-24
相关资源
相似解决方案