I'm using this method to copy files . It works perfectly for all simple file types such as csv
, txt
, pdf
etc . . . except xlsx
. I don't know why Excel
file doesn't want to be copied . It gets corrupted
public static void copyFileFromTo(File source, File dest) {
InputStream input = null;
OutputStream output = null;
try {
input = new FileInputStream(source);
output = new FileOutputStream(dest);
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = input.read(buf)) > 0) {
output.write(buf, 0, bytesRead);
}
input.close();
output.close();
}
catch (IOException e) {
JOptionPane.showMessageDialog(null, e.getMessage() );
System.exit(-1);
}
}