JAVA代码将xls文件上传到服务器报错
接手一个项目,发现上传文件报错。
指定上传.xls文件,报错系统找不到指定路径
代码:
UpLoadForm类:
public class UpLoadForm extends ActionForm {
/**
*
*/
private static final long serialVersionUID = 1L;
public UpLoadForm() {}
/**
* The file that the user has uploaded
*/
private FormFile formFile;
public FormFile getFormFile() {
return this.formFile;
}
public void setFormFile(FormFile formFile) {
this.formFile = formFile;
}
/**
* The name of the file - only for displaying results
*/
private String fname;
public String getFname() {
return this.fname;
}
public void setFname(String fname) {
this.fname = fname;
}
/**
* The size of the file - only for displaying results
*/
private String size;
public String getSize() {
return this.size;
}
public void setSize(String size) {
this.size = size;
}
}
jsp(JSP检查没问题)
<html:form styleId="uploadForm" method="post"
enctype="multipart/form-data"
action="/service/blacklist/blackListAction.do?method=importBlackLists">
<input type="button" value="上传" name="button_import"
class="button_style" onclick="importBlackList();">
<td class="t_15">
选择文件:
</td>
<td colspan="3" class="t_35" >
<html:file style="width:50%" property="blackListFile" />
UploadUtil 类:
public class UploadUtil {
/**上传文件缓冲区的大小*/
public static final int UPLOAD_BUFFER_SIZE = 8192;
public static void upload(InputStream fis, String toFilePath) throws SystemException {
BufferedInputStream stream = null;
BufferedOutputStream bos = null;
try {
stream = new BufferedInputStream(fis); //把文件读入
bos = new BufferedOutputStream(new FileOutputStream(toFilePath));//建立一个上传文件的输出流
int bytesRead = 0;
&nbs