I am trying to copy a PDF file from 1 location to another, but once I run the following code, I am unable to open the PDF (it is showing the following error.)
There was an error opening this document. The file is damaged and could not be repaired
public class BinaryFileTransfer {
private static String INPUT_FILE = "C:\\Users\\sashwat\\Desktop\\a.pdf";
private static String OUTPUT_FILE = "C:\\Users\\sashwat\\Desktop\\a-copy.pdf";
public static void main(String args[]) throws Exception {
InputStream is = new BufferedInputStream(new FileInputStream(INPUT_FILE));
OutputStream wos = new BufferedOutputStream(new FileOutputStream(OUTPUT_FILE));
int len = 0;
byte[] brr = new byte[1000];
while ((len = is.read(brr)) != -1) {
wos.write(brr, 0, len);
}
}
}
Can someone help me as to what exactly am I doing wrong?