使用位元組流復制圖片和視頻
需要得方法:
一、FileOutputStream(String name)輸出流
1、write();寫入資料
2、close()關閉流,釋放與此流相關的系統資源
(之前寫了沒保存,所以不多介紹>.<)
二、FileInputStream(String name)輸入流
1、read();讀取資料,讀完回傳-1
2、close()關閉流,釋放與此流相關的系統資源
復制圖片
FileOutputStream fos = null;
FileInputStream fis = null;
try
{
fos = new FileOutputStream("src//file//zls.jpeg");
fis = new FileInputStream("C://img//timg.jpeg");
int data;
while((data = fis.read()) != -1) {
fos.write(data);
}
}
catch (IOException e) {
}finally {
try {
if(fos != null)
fos.close();
} catch (Exception e2) {
}
}
}

結果:

圖片復制的格式不同也是可行的,
復制視頻
FileOutputStream fos = null;
FileInputStream fis = null;
try
{
fos = new FileOutputStream("src//file//1.mp4");
fis = new FileInputStream("C://mp4//kk 2020-09-13 19-54-01.mp4");
int data;
while((data = fis.read()) != -1) {
fos.write(data);
}
}
catch (IOException e) {
}finally {
try {
if(fos != null)
fos.close();
} catch (Exception e2) {
}
}
}

結果如下:

復制視頻和圖片的方法都是一樣,都是采用位元組流來讀取并輸出,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/233945.html
標籤:其他
上一篇:騰訊、百度、小米、網易等前端實習面經(含面試題及決議)
下一篇:使用lame解碼mp3
