What are possible reasons for java.io.IOException: "The filename, directory name, or volume label syntax is incorrect"

This can occur when filename has timestamp with colons, eg. myfile_HH:mm:ss.csv Removing colons fixed the issue.


Try this, as it takes more care of adjusting directory separator characters in the path between targetPath and filename:

File targetFile = new File(targetPath, filename);

I just encountered the same problem. I think it has to something do with write access permission. I got the error while trying to write to c:\ but on changing to D:\ everything worked fine. Apparently Java did not have permission to write to my System Drive (Running Windows 7 installed on C:)