繁体   English   中英

创建视频(.mp4)文件android的副本

[英]Create a copy of video (.mp4) file android

我想将现有的视频文件复制到另一个视频文件。

我试图这样做:

    byte c;
    try {
        FileOutputStream newFile = new FileOutputStream (VIDEO_PATH_TMP);
        FileInputStream oldFile = new FileInputStream (VIDEO_PATH);
        while ((c = (byte) oldFile.read()) != -1) {
            newFile.write(c);
        }

        newFile.close();
        oldFile.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

但这是行不通的。 输出文件已创建,但我看不到视频。

我该如何实施?

谢谢!

好的,我找到了答案,这是代码:

 try {

        FileOutputStream newFile = new FileOutputStream (VIDEO_PATH_TMP);
        FileInputStream oldFile = new FileInputStream (VIDEO_PATH);

         // Transfer bytes from in to out
        byte[] buf = new byte[1024];
        int len;
        while ((len = oldFile.read(buf)) > 0) {
            newFile.write(buf, 0, len);
        }
        newFile.close();
        oldFile.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

我刚刚添加了Buffer数组,它解决了问题:)

我认为您应该在关闭之前致电冲洗:

newFile.flush();
newFile.close();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM