java将inputStream转换为base64字符串 [英] java convert inputStream to base64 string
本文介绍了java将inputStream转换为base64字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一种方法可以将inputStream转换为String,并将其编码为base64,对吧?
在我的函数中,我得到了InputStream参数,需要将它插入到我的Oracle数据库表的BLOB字段中。有没有办法做到这一点? (我的数据库对象包含保存图像的字符串字段,但我找不到任何方法将inputStream转换为base64格式的字符串)
谢谢!
There is a way to convert inputStream to a String, and encode it to base64, right? In my function, I get InputStream param, and need to insert it into the BLOB field in my Oracle database table. Is there a way to do that? (my database object contains string field to save the image, but I don't find any way to convert the inputStream to string in base64 format) Thank you!
推荐答案
您可以使用Base64 API尝试这样的事情。
You can try something like this using the Base64 API.
InputStream finput = new FileInputStream(file);
byte[] imageBytes = new byte[(int)file.length()];
finput.read(imageBytes, 0, imageBytes.length);
finput.close();
String imageStr = Base64.encodeBase64String(imageBytes);
使用此:
这篇关于java将inputStream转换为base64字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文