其他分享
首页 > 其他分享> > 文件 base64 相互转换

文件 base64 相互转换

作者:互联网

public static void main(String[] args) {
    try {
        //文件转base64
       File file = new File("D:\\lib\\111.txt");
       FileInputStream inputStream = new FileInputStream(file);
       byte[] b = new byte[inputStream.available()];
       inputStream.read(b);
        String s = org.springframework.util.Base64Utils.encodeToString(b);
        System.out.println(s);

        //base64 转文件
        byte[] bytes = Base64Utils.decodeFromString(s);
        FileOutputStream os = new FileOutputStream("D:\\lib\\bbb.txt");
        os.write(bytes);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

标签:转换,base64,inputStream,printStackTrace,file,相互,new,byte
来源: https://blog.csdn.net/zxzzxzzhhms/article/details/118255522