我想在sqlite中保存3gp文件,而不是3gp文件的路径。 1. 是否可以在sqlite中保存3gp文件? 2.怎么做? 3. 如果是,创建后会产生什么类型的问题?
修改:
我能够使用 blob 将图像文件保存到 sqlite 中,对于图像,我从“位图到字节数组”转换以进行写入,并从“字节数组到位图”转换以进行读取。但对于 3gp 文件我无法写入和读取它。
最佳答案
- 尝试 Base64 编码/解码技术。 获取视频的输入流并使用Base64编码为字符串。
试试这个代码:-
private String downloadVideo(String url)
{
String video = "";
URL u = null;
InputStream is = null;
try {
u = new URL(url);
is = u.openStream();
HttpURLConnection huc = (HttpURLConnection)u.openConnection();//to know the size of video
if(huc != null)
{
InputStream inputStream = huc.getInputStream();
byte[] buff = new byte[8000];
int bytesRead = 0;
ByteArrayOutputStream bao = new ByteArrayOutputStream();
while((bytesRead = inputStream.read(buff)) != -1) {
bao.write(buff, 0, bytesRead);
}
byte[] data = bao.toByteArray();
video = Base64.encodeBytes(data);
}
}catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
if(is != null){
is.close();
}
}catch (IOException ioe) {
}
}
return video;
}
然后您可以将字符串存储到数据库中。从数据库获取时,您可以将字符串解码到输入流中并获取真实的视频。
- 尝试以下链接,您将获得 BLOB 技术:-
http://www.helloandroid.com/tutorials/store-imagesfiles-database
但是将视频存储到数据库中并不是一个好主意,它会增加数据库的大小和查询的执行时间。
更多内容请看:-
关于android - 如何在sqlite中保存3gp文件(不是路径)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19376629/