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

364 Views Asked by At

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:

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

so the build.gradle.kts file builds correctly.

What else should I import? What am I missing?

1

There are 1 best solutions below

0
Thomas K. On

Javalin's UploadedFile has no property named name. However, it has filename, so this may work (not tested):

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