Copy a file in Java


2007-09-12 Digg! icurtain Delcious icurtain

public static void copyFile(String sourceFile, String filePath, String destinationFile) {

try {
FileInputStream streamSource = new FileInputStream(sourceFile);
FileOutputStream streamDest = new FileOutputStream(filePath + destinationFile);

byte[] buffer = new byte[1024];
int i = 0;
while ((i = streamSource.read(buffer)) != -1) {
streamDest.write(buffer, 0, i);
}
streamSource.close();
streamDest.close();

} catch (IOException e) {
// LOG.debug("file(input|output)stream error: " + e);
}