文件 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();
    }
}
上一篇:网络编程


下一篇:Tomcat_ServletInputStream#readLine读取一行数据