0
我卡住了......我跟着几个教程,但我不知道我的问题是什么......我需要在Repertoir C:\中加载文件 但我不明白做我卡在文件上传(allways不正在上传)
这是我
<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>
这是我对豆
@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());
}
}
}
梅索德这是它allaws显示我的错误消息时上传文件
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)
当我加入这个 uploadDirectory d:\ PDF参数值> –
FERESSS
2013-04-30 09:28:30
它工作正常..why? – FERESSS 2013-04-30 09:28:46