prader6

把流的形式转化为Base64

public class Test2 {
    public static String get() throws IOException {

        InputStream resourceAsStream = Test2.class.getResourceAsStream("/image/image_1.png");
        BufferedInputStream bufferedInputStream = new BufferedInputStream(resourceAsStream);
        byte[] bytes = new byte[bufferedInputStream.available()];
        bufferedInputStream.read(bytes);
        BASE64Encoder base64Encoder = new BASE64Encoder();
        String encode = base64Encoder.encode(bytes);
        System.out.println(encode);
        bufferedInputStream.close();
        return encode;

    }
}

 

posted on 2019-04-12 19:17  prader6  阅读(1015)  评论(0编辑  收藏  举报

导航