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

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存储))