I have the following code to upload the files, when I use the file.getNeme it sh
ID: 3537785 • Letter: I
Question
I have the following code to upload the files, when I use the file.getNeme it shows the temporary file name that has the tmp extension, how can I find the extension of the actual upload file? the file that I am uploading is called test.jpg
import java.io.File;
import org.apache.commons.io.FileUtils;
public class FileUploder {
private File file;
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
......
System.out.println("file:" +file.getName());
try {
File fileToCreate = new File(filePath,name);
FileUtils.copyFile(file, fileToCreate);
} catch (IOException ex) {
ex.printStackTrace();
}
......
Explanation / Answer
You should not use file.getName()
http://struts.apache.org/release/2.0.x/docs/file-upload.html#FileUpload-BasicUsage
up vote0down voteaccepted You should not use file.getName()
http://struts.apache.org/release/2.0.x/docs/file-upload.html#FileUpload-BasicUsage