java convert inputStream to base64 string

前端 未结 4 607
说谎
说谎 2021-02-07 01:47

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 Oracl

4条回答
  •  长情又很酷
    2021-02-07 02:33

    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);
    

    Use this:

    http://commons.apache.org/proper/commons-codec/archives/1.9/apidocs/org/apache/commons/codec/binary/Base64.html

提交回复
热议问题