我被卡住了......我遵循了几个教程,但我不知道我的问题是什么......我需要在 Repertoir C:\ PDF 中上传文件,但我没有做
这是我的
<h:form enctype="multipart/form-data">
<p:fileUpload
mode="advanced"
fileUploadListener="#{composantbean.upload}"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/" sizeLimit="100000" description="Select Images"
auto="true"/>
</h:form>
这是我在 bean 上的方法
@ManagedBean(name="composantbean")
@SessionScoped
public class Composantbeam {
private String destination="C:\\PDF\\";
public void upload(FileUploadEvent event) {
FacesMessage msg = new FacesMessage("Success! ", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
// Do what you want with the file
try {
copyFile(event.getFile().getFileName(), event.getFile().getInputstream());
} catch (IOException e) {
e.printStackTrace();
}
}
public void copyFile(String fileName, InputStream in) {
try {
// write the inputStream to a FileOutputStream
OutputStream out = new FileOutputStream(new File(destination + fileName));
int read = 0;
byte[] bytes = new byte[1024];
while ((read = in.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
in.close();
out.flush();
out.close();
System.out.println("New file created!");
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
这是我上传文件时显示的错误消息
C:\PDF\C:\Documents and Settings\Admin\Bureau\login.png (Syntaxe du nom de fichier, de répertoire ou de volume incorrecte)
C: \ PDF \ C: \ Documents and Settings \ Admin \ Desktop \ login.png (syntax file name, directory or incorrect volume)