Reputation: 267
I get the following exception:
D:\Try\folder\filename_1_06_09_2014_12:46:18.txt (The filename, directory name, or volume label syntax is incorrect)
While using timestamp in renaming filename here:
for (int i = 0; i < children.length; i++) {
String fileName = new SimpleDateFormat("MM_dd_yyyy_hh:mm:ss").format(new Date());
copyDirectory(new File(sourceLocation, children[i]), new File(targetLocation, files+"_"+fileName+".txt"));
}
I can't figure it out where I use invalid characters in windows filename. Any suggestions please?
Upvotes: 17
Views: 83542
Reputation: 37
This problem can also be risen because of the permissions at level security you have at the folder you are trying to open or file you are trying to write.
Upvotes: -2
Reputation: 805
You cannot use colons :
to create file in Windows. If you absolutely need the timestamp then you could try to add underscores for them as well.
Upvotes: 35