我有这个Java代码:
public void myMethod(Exception ex, Path path) {
try {
addExceptionToTree(ex.getClass().getSimpleName(), path.toFile().getCanonicalPath());
LOGGER.log(Level.INFO, "{0} for: {1}", new Object[]{ex.getClass().getSimpleName(), path.toFile().getCanonicalPath()});
} catch (IOException ex2) {
System.out.println("myMethod.ex:" + ex);
System.out.println("myMethod.path:" + path);
LOGGER.log(Level.SEVERE, null, ex2);
}
}
此调用引发异常
path.toFile().getCanonicalPath()
我的输出是:
myMethod.ex:java.io.IOException: The parameter is incorrect
myMethod.path:G:\Macintosh HD\Applications\UniFi-Discover.app\Contents\Plugins\jre1.8.0_181.jre\Contents\MacOS\libjli.dylib
Jan 24, 2019 12:09:46 AM org.my.OwnClass myMethod
SEVERE: null
java.io.IOException: The parameter is incorrect
at java.io.WinNTFileSystem.canonicalize0(Native Method)
at java.io.WinNTFileSystem.canonicalize(Unknown Source)
at java.io.File.getCanonicalPath(Unknown Source)
at org.my.OwnClass.addExceptionToTree(OwnClass.java:660)
我在VirtualBox 5.2和Windows 10上运行。
如您所见:
G:\Macintosh HD\Applications\UniFi-Discover.app\Contents\Plugins\jre1.8.0_181.jre\Contents\MacOS\libjli.dylib
结构良好。
是由于路径中的空间吗?如何执行此任务(getCanonicalPath()
)?
我确实有同样的问题,任何人都可以帮忙吗?