java convert inputStream to base64 string

前端 未结 4 606
说谎
说谎 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:49

    There is nice way to do this is using IOUtils to convert the InputStream into a Byte Array...

    something like

        InputStream is;
        byte[] bytes = IOUtils.toByteArray(is);
    

    Here you can use Base64 to convert Byte Array to String.

    Sample Code

        String encoded = Base64.getEncoder().encodeToString(bytes);
    

    Now you can use your String.

提交回复
热议问题