gpt4 book ai didi

grails - 如何在grails中获取文件扩展名?

转载 作者:行者123 更新时间:2023-12-02 13:51:19 24 4
gpt4 key购买 nike

I recently started working on grails and i want to know how to get the extension of a file. Ex: test.txt. I want to check extension(txt)? any clue?

最佳答案

这是另一种方式。使用正则表达式。

def fileName = 'something.ext'
def matcher = (fileName =~ /.*\.(.*)$/)

if(matcher.matches()) {
def extension = matcher[0][1]

if(extension in ['jpg', 'jpeg', 'png']) {
// Good to go
println 'ok'
} else {
println 'not ok'
}
} else {
println 'No file extension found'
}

关于grails - 如何在grails中获取文件扩展名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32916869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com