Does groovy have an easy way to get a filename without the extension?

前端 未结 10 1096
-上瘾入骨i
-上瘾入骨i 2020-12-14 14:41

Say I have something like this:

new File(\"test\").eachFile() { file->  
println file.getName()  
}

This prints the full filename of eve

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-14 15:20

    The cleanest way.

    String fileWithoutExt = file.name.take(file.name.lastIndexOf('.'))

提交回复
热议问题