【发布时间】:2017-12-14 09:22:15
【问题描述】:
我正在尝试将路径拆分为父级和名称。
尝试时
String path = "/root/file"
File file = new File(path)
println("Name: " + file.name)
println("Parent: " + file.parent)
我们得到
Name: file
Parent: /root
使用 Windows 路径 C:\\root\\file.exe 我们得到
Name: C:\root\file.exe
Parent: null
这是预期的行为吗?如果是这样,我如何为 Windows 路径获得相同的结果? (如果可能,请不要使用正则表达式)
【问题讨论】:
-
Java (stackoverflow.com/questions/3548775/…) 的这个答案也应该适用于 Groovy。