gpt4 book ai didi

java - 用 Java 编写视频文件

转载 作者:搜寻专家 更新时间:2023-11-01 03:27:24 25 4
gpt4 key购买 nike

我正在尝试找到一种保存视频文件的方法。最初我将视频文件作为 blob 数据放入数据库,现在,我试图取回 blob 数据,将其转换为字节,然后将其写入新文件。我已经成功地做到了这一点,但问题是,我无法运行生成的文件。我尝试存储、检索和写入 .flv 和 .mp4 文件,但都不起作用:/谁能帮助我?非常感激! :)

这是我的代码::)

try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(connectionURL, "root","password");
Statement st1 = (Statement) con.createStatement();
PreparedStatement pstmt = null;
ResultSet rs = null;
pstmt = con.prepareStatement("SELECT video_file from video where video_id = " + video_id);
rs = pstmt.executeQuery();
Blob blob = null;
byte[] blyte = null;
if(rs.next()) {
blob = rs.getBlob("video_file");
InputStream is = blob.getBinaryStream();
FileOutputStream fos = new FileOutputStream("C:\\Downloads\\file2.mp4");
int b = 0;
while(b != -1){
fos.write(b);
b = bis.read();
}
}
//exceptions beyond this point
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
} catch (ClassNotFoundException e) {
} catch (SQLException e) {
} catch (FileNotFoundException e) {
} catch (IOException e) {
}

最佳答案

在 while 循环的第一次迭代中有一个 '\0' 字节写入 fos,它不是来自 bis.read()。

关于java - 用 Java 编写视频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9931344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com