本文介绍了将视频转换为字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想在Java中将视频内容转换为字节吗,有什么机构可以帮助我做到这一点?
want to convert the content of video to byte in java could any body help me to do that?
推荐答案
package Practice;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Temp {
public static void main(String[] args)
{
File file = new File("c:/EventItemBroker.java");
byte[] b = new byte[(int) file.length()];
try
{
FileInputStream fileInputStream = new FileInputStream(file);
fileInputStream.read(b);
for (int i = 0; i < b.length; i++) {
System.out.print((char)b[i]);
}
} catch (FileNotFoundException e) {
System.out.println("File Not Found.");
e.printStackTrace();
}
catch (IOException e1)
{
System.out.println("Error Reading The File.");
e1.printStackTrace();
}
}
}
还可以看看:
ByteArray [ ^ ]
FileInputStream [ ^ ]
文件(URI) [ ^ ]
另类:
Also have look:
ByteArray[^]
FileInputStream[^]
File(URI)[^]
Alternative:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileInputStream fis = new FileInputStream(new File(yourUri));
byte[] buf = new byte[1024];
int n;
while (-1 != (n = fis.read(buf)))
baos.write(buf, 0, n);
byte[] videoBytes = baos.toByteArray();
Please refer this: Divide the video to bytes[^]
这篇关于将视频转换为字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!