问题描述
当我尝试运行此代码时:
FileUtils.copyInputStreamToFile(file.getContent(),new File("upload/" + file.getName()));
我收到此错误:
error: cannot find symbol
symbol: method getName()
location: variable file of type UploadedFile
我已经导入了这些:
import java.io.*;
import org.apache.commons.io.FileUtils;
我正在使用 Gradle,我已经在 build.gradle.kts 中添加了这个依赖项:
implementation(group= "commons-io",name= "commons-io",version= "2.5")
所以 build.gradle.kts 文件构建正确。
我还应该导入什么?我错过了什么?
解决方法
Javalin 的 UploadedFile
没有名为 name
的属性。但是,它有 filename
,所以这可能有效(未经测试):
FileUtils.copyInputStreamToFile(file.getContent(),new File("upload/" + file.getFilename()));