Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The filename, directory name or volume label syntax incorrect

Tags:

java

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?

like image 585
user3721625 Avatar asked Jun 09 '14 08:06

user3721625


1 Answers

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.

like image 59
NcDreamy Avatar answered Sep 19 '22 14:09

NcDreamy