简体   繁体   English

文件名,目录名或卷标语法不正确

[英]The filename, directory name or volume label syntax incorrect

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) D:\\ Try \\ folder \\ filename_1_06_09_2014_12:46:18.txt(文件名,目录名或卷标语法不正确)

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. 我无法弄清楚我在Windows文件名中使用无效字符的位置。 Any suggestions please? 有什么建议吗?

You cannot use colons : to create file in Windows. 您不能使用冒号:在Windows中创建文件。 If you absolutely need the timestamp then you could try to add underscores for them as well. 如果您绝对需要时间戳,那么您也可以尝试为它们添加下划线。

You can't have colons in filenames on Windows file systems, they can only be used to separate drives from the rest of the path: 您不能在Windows文件系统上的文件名中使用冒号,它们只能用于将驱动器与路径的其余部分分开:

D:\Try\folder\filename_1_06_09_2014_12:46:18.txt 
Issue is here ------------------------^--^

只需使用有效的charachters更改根目录名称即可

由于您尝试打​​开的文件夹或尝试编写的文件具有级别安全权限,因此也可能会出现此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 文件名,目录名称或卷标签语法不正确 - The filename, directory name or volume label syntax is incorrect 文件名,目录名或卷标语法是不正确的java - The filename, directory name, or volume label syntax is incorrect java 文件名,目录名或卷标语法不正确 - Kotlin - Maven - The filename, directory name or volume label syntax is incorrect - Kotlin - Maven CMD 中的“C:\”、文件名、目录名或卷 label 语法不正确 - 'C:\' in CMD, the filename, directory name, or volume label syntax is incorrect Java/Webdav:文件名、目录名或卷 label 语法不正确” - Java/Webdav: The filename, directory name, or volume label syntax is incorrect” 在 VSCode 中出现错误“文件名、目录名或卷 label 语法不正确” - Error "The filename, directory name, or volume label syntax is incorrect" in VSCode FileNotFoundException(文件名,目录名称或卷标签语法不正确) - FileNotFoundException (The filename, directory name, or volume label syntax is incorrect) JSP-文件名,目录名或卷标签语法不正确 - JSP - The filename, directory name, or volume label syntax is incorrect 文件名,目录名或卷标签语法不正确-如何在属性文件中指定文件路径 - The filename, directory name, or volume label syntax is incorrect - how to specify file path in properties file java.io.IOException 的可能原因是什么:“文件名、目录名或卷标语法不正确” - What are possible reasons for java.io.IOException: “The filename, directory name, or volume label syntax is incorrect”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM