简体   繁体   English

file.getName() 找不到方法 getName() 的符号(使用 Gradle 和 Javalin)

[英]file.getName() cannot find symbol for method getName() (using Gradle and Javalin)

When i try to run this code:当我尝试运行此代码时:

FileUtils.copyInputStreamToFile(file.getContent(), new File("upload/" + file.getName()));

I get this error:我收到此错误:

error: cannot find symbol
symbol:   method getName()
location: variable file of type UploadedFile

I have already imported these:我已经导入了这些:

import java.io.*;
import org.apache.commons.io.FileUtils;

I'm working with Gradle and I have already added to the dependencies in build.gradle.kts this one:我正在使用 Gradle 并且我已经添加到 build.gradle.kts 中的依赖项中:

 implementation(group= "commons-io", name= "commons-io", version= "2.5")

so the build.gradle.kts file builds correctly.因此 build.gradle.kts 文件构建正确。

What else should I import?我还应该导入什么? What am I missing?我错过了什么?

Javalin's UploadedFile has no property named name . Javalin 的UploadedFile没有名为name的属性。 However, it has filename , so this may work (not tested):但是,它有filename ,所以这可能有效(未经测试):

FileUtils.copyInputStreamToFile(file.getContent(), new File("upload/" + file.getFilename()));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM