0

I am trying to create some data files with date & time in the file name on Windows. The file name is like "C:/data-2018-11-07 11:02:42.log". However when I tried the folowing code:

File file = new File("C:/data-2018-11-07 11:02:42.log").getCanonicalFile();

An Exception come out:

java.io.IOException: The filename, directory name, or volume label syntax is incorrect
    at java.io.WinNTFileSystem.canonicalize0(Native Method)
    at java.io.WinNTFileSystem.canonicalize(WinNTFileSystem.java:428)
    at java.io.File.getCanonicalPath(File.java:618)
    at java.io.File.getCanonicalFile(File.java:643)

How can I remove this exception? I tried with replacing the ":" with "_", it worked good. What I can do to use the ":"?

And I was using Java 8.

Xinlong
  • 23
  • 3

1 Answers1

0

Finally, I found out the reason. The reason is that Windows does not allow ":" in file path. I used a similar one as described in How to get a file in Windows with a colon in the filename?, and everything is fine.

Xinlong
  • 23
  • 3