嗨,伙计们,我是java的初学者。我目前在 apache wicket 工作,这是一个基于 java 的框架。我正在尝试创建一个加载按钮来选择和上传特定文件夹中的多个文件。我已经有了这段代码,我可以使用它来选择和上传单个文件,但我很困惑做同样的选择和上传多个文件。
提前致谢
public class HomePage extends WebPage {
private FileUploadField fileUpload;
private String UPLOAD_FOLDER = "C:\\";
public HomePage(final PageParameters parameters) {
add(new FeedbackPanel("feedback"));
Form<?> form = new Form<Void>("form") {
@Override
protected void onSubmit() {
final FileUpload uploadedFile = fileUpload.getFileUpload();
if (uploadedFile != null) {
//write to a new file
File newFile = new File(UPLOAD_FOLDER
+ uploadedFile.getClientFileName());
if (newFile.exists()) {
newFile.delete();
}
try {
newFile.createNewFile();
uploadedFile.writeTo(newFile);
///file which is diplayed after uploading
info("" + uploadedFile.getClientFileName());
}
catch (Exception e)
{
throw new IllegalStateException("Error");
}
}
}
};
// Enable multipart mode (need for uploads file)
form.setMultiPart(true);
// max upload size, 10k
form.setMaxSize(Bytes.kilobytes(1000));
form.add(fileUpload = new FileUploadField("fileUpload"));
add(form);
}
}