【发布时间】:2015-02-24 19:17:36
【问题描述】:
我正在尝试将图像文件上传到本地文件夹并收到文件未找到错误。上传文件的错误消息中指出的位置不正确。实际上,错误中显示的文件位置是我的源位置和目标位置的组合。我正在尝试从我的桌面将文件上传到“C:/Users/sam//File/Upload/”。这是错误代码,
错误信息
java.io.FileNotFoundException: C:\Users\sam\File\Upload\C:\Users\sam\Desktop\test.jpg (The filename, directory name, or volume label syntax is incorrect)
我的课程文件
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import org.apache.commons.io.IOUtils;
import org.primefaces.event.FileUploadEvent;
@ManagedBean
public class FileUploadView {
private String fileUploadFolder = "C:/Users/sam/File/Upload/";
public void handleFileUpload(FileUploadEvent event) {
FacesMessage message = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
try {
File targetFolder = new File(fileUploadFolder);
InputStream input = event.getFile().getInputstream();
OutputStream output = new FileOutputStream(new File(targetFolder,
event.getFile().getFileName()));
try {
IOUtils.copy(input, output);
} finally {
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(output);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
还有我的html
<p:fileUpload fileUploadListener="#{fileUploadView.handleFileUpload}"
mode="advanced" dragDropSupport="false" update="messages"
sizeLimit="100000000" fileLimit="1"
allowTypes="/(\.|\/)(gif|jpe?g|png|xlsx|jpg)$/" />
我也尝试了example from BalusC,仍然遇到同样的错误,ui 与 primefaces5.1。
【问题讨论】:
-
您的示例按预期对我有用,没有任何问题。我使用了“Mojarra 2.2.9”+ Tomcat 7 + Primefaces 5.1。文件复制成功。
-
@ pL4Gu33-我知道这是一个奇怪的问题,它以前工作过,现在我开始遇到问题了。我有相同的“Mojarra 2.2.9”+ Tomcat 7 + Primefaces 5.1。有什么其他推荐的地方吗?
-
我想知道为什么我会像这样获取文件位置 C:\Users\sam\File\Upload\C:\Users\sam\Desktop\test.jpg?有什么我不明白的错字吗?
-
好的,我发现这个问题只出现在我系统中的 IE8 上。在 Forefox 中,它运行良好。这是来自 primefaces 还是 jsf 的错误?
-
IE 不是真正的浏览器@KodS,IE8 更不用说
标签: internet-explorer file-upload jsf-2 primefaces filenotfoundexception