我在XHTML中创建一个页面,使用primeface <p:fileUpload>
组件上传多个文件。
问题是:
如果我选择20个文件。复制的文件有时可能是12个,有时是17个。我无法理解我需要修复哪种错误。我在下面粘贴了Java和xhtml代码。
XHTML:
<h:head>
<title>Sample Page</title>
</h:head>
<h:body>
<f:event listener="#{MessagePanel.initializePageAttributes}" type="preRenderComponent"/>
<h:form enctype="multipart/form-data">
<p:panel id="multiUploadId" rendered="#{!MessagePanel.renderedPanel}">
<h:panelGrid columns="3">
<h:outputText value="Upload:"/>
<p:fileUpload value="#{MessagePanel.file}" mode="advanced" multiple="true"
fileUploadListener="#{MessagePanel.fileUploadListener}" update="multiUploadId">
</p:fileUpload>
</h:panelGrid>
</p:panel>
</h:form>
</h:body>
</html>
Java代码:
public void fileUploadListener(FileUploadEvent e)
{
try
{
// Get uploaded file from the FileUploadEvent
// Print out the information of the file
this.file = e.getFile();
System.out.println("Uploaded File Name Is :: " + file.getFileName() + " :: Uploaded File Size :: " + file.getSize());
File destFile = new File("/home/nafeel/Desktop/upload/" + file.getFileName());
FileUtils.copyInputStreamToFile(file.getInputstream(), destFile);
e.getComponent().setTransient(false);
}
catch (IOException ex)
{
System.out.println("IO exception: "+ex.getMessage());
}
}