【发布时间】:2012-04-07 18:02:45
【问题描述】:
我使用以下代码获取路径
Path errorFilePath = FileSystems.getDefault().getPath(errorFile);
当我尝试使用 File NIO 移动文件时,我收到以下错误:
java.nio.file.InvalidPathException: Illegal char <:> at index 2: \C:\Sample\sample.txt
我也尝试使用 URL.encode(errorFile) 导致同样的错误。
【问题讨论】:
-
我想知道为什么我的主角是'/',而不是问题中的'\'。我正在使用 Windows 10、Java 8、Spring 3.2.14.RELEASE。
-
我们案例中的错误来自:
ClassLoader.getSystemResource("something").getPath()- 在 Windows 上,它正在从file:/C:/mypath删除file: