【发布时间】:2013-04-12 07:53:02
【问题描述】:
我正在读取一个以字节为单位的视频文件数据并发送到另一个文件,但接收到的视频文件播放不正常并出现抖动。
谁能解释一下为什么会发生这种情况并感谢解决方案。
我的代码如下
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。您需要将文件复制到块中 -
感谢您的回复。我想加密数据以便将文件读入字符串。
-
还要从 write 方法中删除“\n”。
标签: java file file-io copy video-streaming