I am trying to upload a file to two different directories. But somehow it copies the file to one directory , but fails to copy in second directory.
My src directory for file is something like this
C:\path\to\temp
And my destination directories are like this
C:\path\to\destination\1 & C:\path\to\destination\2
directories 1 and 2 are getting created on the fly.
This is what I am using in my code
public final static boolean move(String src, String dest, boolean createDestDir, boolean overwrite) {
try{
if(src == null || src.length() == 0 || dest == null || dest.length() == 0){
return false;
}
File srcFile = new File(src);
if(srcFile.isFile() == false){
return false;
}
String destPath = path(dest);
String destFileName;
if (destPath.equals(dest)) {
destFileName = srcFile.getName();
} else {
destFileName = name(dest);
}
File destDir = new File(destPath);
if (destDir.exists() == false) {
if (createDestDir == false) return false;
if (destDir.mkdirs() == false) {
return false;
}
}
File destFile = new File(destPath + destFileName);
if (destFile.exists()) {
if (overwrite == false) return false;
if (destFile.delete() == false) {
return false;
}
}
return srcFile.renameTo(destFile);
}
}
During my loop srcFile.isFile()
is failing second time, it works first time, but fails second time.