美文网首页
java输入输出图片(base64编解码,oracle-blob

java输入输出图片(base64编解码,oracle-blob

作者: 屎倒淋头还嚼便 | 来源:发表于2019-10-10 19:52 被阅读0次
InputStream in = new FileInputStream("C:\\Users\\tom\\Desktop\\1234.png");
        int available = in.available(); // 读取文件的字节个数
        byte[] fileBytes = new byte[available];
        in.read(fileBytes); // 将文件读取到字节数组b中
        
        Encoder encoder = java.util.Base64.getEncoder();
        byte[] encode = encoder.encode(fileBytes); // base64编码
        Blob blob = new SerialBlob(encode); // 字节数组转为Blob
        byte[] bytes = blob.getBytes(1, (int)blob.length()); // Blob转为字节数组
        
        Decoder decoder = Base64.getDecoder();
        byte[] decode = decoder.decode(bytes); // 解码
        
        OutputStream out = new FileOutputStream("C:\\Users\\tom\\Desktop\\12345.png");
        out.write(decode,0,decode.length);
        out.flush();
        out.close();

相关文章

网友评论

      本文标题:java输入输出图片(base64编解码,oracle-blob

      本文链接:https://www.haomeiwen.com/subject/hmlbyctx.html