Android : Copy RawFile to Sdcard (video mp4)

前端 未结 3 873
失恋的感觉
失恋的感觉 2020-12-15 13:51

What is wrong on this code ?
I\'ve a Raw file in my project (mp4 videofile),
when i do this, and then i retreive file from SDcard file are not identical so video can

相关标签:
3条回答
  • 2020-12-15 14:12

    If you use an InputStream to read, use an OutputStream to write, i.e. a BufferedOutputStream-wrapped FileOutputStream. Also, your code is pretty inefficient, as it only copies one byte at a time. I'd suggest creating a byte array buffer and using these relevant read/write methods:

    int BufferedInputStream.read(byte[] buffer, int offset, int length)
    void BufferedOutputStream.write(byte[] buffer, int offset, int length)
    
    0 讨论(0)
  • 2020-12-15 14:20

    It works,thanks

    BufferedOutputStream bufEcrivain = new BufferedOutputStream((new FileOutputStream(f)));
    BufferedInputStream VideoReader = new BufferedInputStream(getResources().openRawResource(R.raw.blow));
    byte[] buff = new byte[32 * 1024];
    int len;
    while( (len = VideoReader.read(buff)) > 0 ){
        bufEcrivain.write(buff,0,len);
    }
    bufEcrivain.flush();
    bufEcrivain.close();
    
    0 讨论(0)
  • 2020-12-15 14:28

    I think you should flush before you close the stream

    bufEcrivain.flush();
    bufEcrivain.close();
    
    0 讨论(0)
提交回复
热议问题