3 回答
TA贡献1844条经验 获得超8个赞
您可以解码 base64 编码的字符串并将其传递byte[]给FileOutputStreamwrite 方法来解决此问题。
String filePath = "C:\\Users\\xyz\\Desktop\\";
String originalFileName = "96172560100_copy2.pdf";
String newFileName = "test.pdf";
byte[] input_file = Files.readAllBytes(Paths.get(filePath+originalFileName));
byte[] encodedBytes = Base64.getEncoder().encode(input_file);
String encodedString = new String(encodedBytes);
byte[] decodedBytes = Base64.getDecoder().decode(encodedString.getBytes());
FileOutputStream fos = new FileOutputStream(filePath+newFileName);
fos.write(decodedBytes);
fos.flush();
fos.close();
添加回答
举报