我正在以字節爲單位讀取視頻文件數據併發送到另一個文件,但收到的視頻文件播放不正常並且發生了聊天。讀取視頻數據並寫入另一個文件java
任何人都可以解釋爲什麼發生這種情況,並感謝解決方案。
我的代碼如下
import java.io.*;
public class convert {
public static void main(String[] args) {
//create file object
File file = new File("B:/music/Billa.mp4");
try
{
//create FileInputStream object
FileInputStream fin = new FileInputStream(file);
byte fileContent[] = new byte[(int)file.length()];
fin.read(fileContent);
//create string from byte array
String strFileContent = new String(fileContent);
System.out.println("File content : ");
System.out.println(strFileContent);
File dest=new File("B://music//a.mp4");
BufferedWriter bw=new BufferedWriter(new FileWriter(dest));
bw.write(strFileContent+"\n");
bw.flush();
}
catch(FileNotFoundException e)
{
System.out.println("File not found" + e);
}
catch(IOException ioe)
{
System.out.println("Exception while reading the file " + ioe);
}
}
}
1)這與流媒體視頻有什麼關係?視頻的來源是一個文件! 2)**您不能將視頻數據視爲字符串或文本!它不是。** –
'new byte [(int)file.length()]'可能會截斷文件中的字節,因爲'int'小於'long'。您需要將文件複製到chunk中 – MadProgrammer
感謝您的回覆。我想加密數據,以便將文件讀入字符串。 – Krish