【发布时间】:2014-06-17 15:58:33
【问题描述】:
我使用简单模式,glassfish 3.0 和 primefaces 3.0
支持豆
私有 UploadedFile 文件; 私有字符串目的地="D:\temp\";
公共无效上传(FleUploadEvent 事件){
System.out.println("upload");
FacesMessage msg = new FacesMessage("Success! ", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
try {
copyFile(event.getFile().getFileName(), event.getFile().getInputstream());
}
catch (IOException e)
{
e.printStackTrace();
}
}
System.out.println("uploaf finished");
public void copyFile(String fileName, InputStream in) { 试试 {
// 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());
}
}
这是我的 jsf 页面
【问题讨论】:
-
请帮助任何人解决它没有在目的地显示的图像
-
显示以下消息未生成任何异常或错误仅简单消息“D:\tmp\C:\Users\admin\Desktop\ulcerimage.jpg(文件名、目录名或卷标语法不正确)"
-
我正在使用上面相同的代码,所以请告诉我在目标位置文件尚未上传
-
有您的文件字段设置器和获取器方法吗?可能会帮助您关注以下链接:stackoverflow.com/questions/14211843/how-to-save-uploaded-file/… 和 stackoverflow.com/questions/18664579/…
-
先生,我在 jsf 页面中使用
上面链接中的这些代码我无法设置到目的地
标签: java jsf primefaces