public void copyFile(String oldPath, String newPath) throws IOException {
(new File(newPath)).mkdirs();
String[] file = new File(oldPath).list();
File fileTemp = null;
String separator = File.separator;
for (int i = 0; i < file.length; i++) {
if (oldPath.endsWith(separator)) {
fileTemp = new File(oldPath + file[i]);
} else {
fileTemp = new File(oldPath + separator + file[i]);
}
if (fileTemp.isFile()) {
FileInputStream fis = new FileInputStream(fileTemp);
if (file[i].endsWith(".txt")) {
fileTemp = new File(oldPath + separator + file[i].substring(0, file[i].length() - 4) + ".sql");
}
FileOutputStream fos = new FileOutputStream(newPath + "/" + fileTemp.getName());
byte[] b = new byte[1024 * 5];
int len;
while ((len = fis.read(b)) != -1) {
fos.write(b, 0, len);
}
fos.flush();
fos.close();
fis.close();
}
if (fileTemp.isDirectory()) {
this.copyFile(oldPath + "/" + file[i], newPath + "/" + file[i]);
}
}
}