When i hit an API through postman i am able to download a pdf file. When i hit the same API through java code i get pdf content in ResponseBody. And i am able to create a new pdf file with the responsebody content but when i open the file it is blank.
my question is how can i create a new file with the same content as in response.
i tried the foll. code to convert the response
file = new File("/home/abc.pdf");
outputStream = new BufferedOutputStream(new FileOutputStream(file));
if (!file.exists()) {
file.createNewFile();
}
byte[] contentInBytes = response.getBody().getBytes();
System.out.println(Arrays.toString(contentInBytes));
outputStream.write(contentInBytes);
outputStream.flush();
outputStream.close();