[英]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.