I am downloading files from aws s3 using the getObject api. Simple text files work fine, but on pdf download my file is corrupted. I am using FileOutputStream and saving contents in a file, but the pdf saved is getting corrupted.
I am not quite sure about the correct java api to use for this purpose and what should be the size of the byte array where the bytes read get written.
I am also curious if using the SDK directly makes sense, or is there are open source wrapper api's available in Java that I could be leveraging.
FileOutputStream fout = new FileOutputStream(new File(destFileName));
byte[] b = new byte[8192];
int bytesRead;
while (true) {
bytesRead = input.read(b);
System.out.println("bytesRead = "+bytesRead );
if (bytesRead==-1)
break;
fout.write(b);
}
fout.flush();
fout.close();