如何通过grails删除保存在文件夹中的文件?

如何通过grails删除保存在文件夹中的文件?,grails,groovy,Grails,Groovy,在y grails应用程序中创建条目时,我正在保存一个.pdf/.docx文件。现在单击Delete按钮,我想从DB中删除该条目,同时还想从文件夹中删除.pdf/.docx文件。 注意:我正在数据库中保存文件的路径。从物理位置删除文件就这么简单- String filePath = fileDomainObject.filePath boolean fileSuccessfullyDeleted = new File(filePath).delete() if(fileSuccessfully

在y grails应用程序中创建条目时,我正在保存一个.pdf/.docx文件。现在单击Delete按钮,我想从DB中删除该条目,同时还想从文件夹中删除.pdf/.docx文件。
注意:我正在数据库中保存文件的路径。

从物理位置删除文件就这么简单-

String filePath = fileDomainObject.filePath
boolean fileSuccessfullyDeleted =  new File(filePath).delete()
if(fileSuccessfullyDeleted ){
    fileDomainObject.delete flush:true
}
else{
    flash.error = "Error in deletion."
    return
}
def file = new File(/C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg/)   
file.delete()