文件转换为字符串

public static String file2String(File file){
        try {
            BufferedReader buffer = new BufferedReader(new FileReader(file));
            StringBuilder sb = new StringBuilder();
            String temp;
            while((temp = buffer.readLine()) !=null ){
                sb.append(temp);
            }
            return sb.toString();
        } catch (IOException e) {
            log.error("======FileService====== 文件转换字符串失败");
            return null;
        }
    }

字符串转base64

 public static String getBase64(String str){
        if(StringUtils.isEmpty(str)){
            return null;
        }
        byte[] b = str.getBytes(StandardCharsets.UTF_8);
        return new BASE64Encoder().encode(b);
    }

base64转文件流

    byte[] fileBytes = Base64.getDecoder().decode(fileBase64.toString().replace("\r\n", ""));