String file = request.getParameter("excelFile");
try {
InputStream stream = new FileInputStream(file);
String filePath = request.getRealPath("/");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
File file2 = new File(file);
if (!(file2.getName().endsWith(".xls"))) {
String errMsg = java.net.URLEncoder.encode(
"文件格式错误,请选择EXCEL文件", "GB2312");
String url = "/common/showError.jsp?str=" + errMsg;
return (new ActionForward(url, true));
}
dir = filePath + "upfile\\student/" + file2.getName();
OutputStream bos = new FileOutputStream(dir);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);//将文件写入服务器
}
bos.close();
stream.close();
} catch (Exception e) {
System.err.print(e);
String errMsg = java.net.URLEncoder.encode("上传文件出错,请重新上传",
"GB2312");
String url = "/common/showError.jsp?str=" + errMsg;
return (new ActionForward(url, true));
◆◆
评论读取中....
请登录后再发表评论!
◆◆
修改失败,请稍后尝试