I have a process where I sync a folder with files that is on a database. There is just below 50000 files that sync. Some of the files sync perfectly; However on one file I receive a File Not Found Exception. I do check if the parent directory exists and I create it if not.
The File writing code is as follows:
for(Map<String,Object> file: fileList)
{
createDirectory(file); //Creates the directory
Blob outBlob = (Blob)file.get("fileData");
InputStream is = outBlob.getBinaryStream();
FileOutputStream fos = new FileOutputStream((String)file.get("path"));
int b = 0;
while ((b = is.read()) != -1)
{
fos.write(b);
}
fos.flush();
fos.close();
}
And the createDirectory method:
public static void createDirectory(Map<String,Object> file) throws IOException
{
// Create parent directory - If directory does not exist
File directory = new File(file.get("parent"));
if (!directory.exists())
{
System.out.println("Parent Directory does not exist, creating ...");
// ...create it
if (!directory.mkdirs())
{
System.out.println("Parent Directory creation failed ...");
}
}
}
This is the line that gives a FileNotFoundException
FileOutputStream fos = new FileOutputStream((String)file.get("path"));
The parent directory is C:\temp\
I do have permissions on the above folder.
The createDirectory method does not log anything to the console as the directory does exist.
I have searched for a few days and cannot see why this one file will fail while the others succeed. Any help would be appreciated.
The above code has been trimmed down and variable names changed. Due to security reasons I am not allowed to give the stack trace. I have tried to duplicate the error but had no luck in doeing so.
PS this is my first time asking on stackoverflow, please forgive me if I broke some standards rule.
Regards,