上传文件 JSP+java
来源:互联网 发布:vscode c 生成exe 编辑:程序博客网 时间:2024/05/02 02:25
2。java
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
preCheck(); //鉴定
FileProperties salarypro =
new FileProperties("/HostRoute.properties");
String outFilepath = salarypro.getProperty("FBSFtpLocalPath").trim();
//outFilepath = "d:/";
String outFilename = outFilepath + "0" + seqNo + ".rar";
File upFile = getUpLoadFile("UploadFile");
byte fileByte[] = new byte[Integer.parseInt(Long.toString(upFile.length()))];
try {
FileInputStream ddd = new FileInputStream(upFile);
ddd.read(fileByte);
ddd.close();
FileOutputStream outf = new FileOutputStream(new File(outFilename));
outf.write(fileByte);
outf.close();
} catch ( IOException e) {
System.err.println( "upload file error! " + e.toString() );
throw new CsiiException("上传文件失败");
}catch( Exception e3 ) {
System.err.println( "upload file error! " + e3.toString() );
throw new CsiiException("上传文件失败");
}
public void preCheck() throws CsiiException {
int maxUpLoadFileSize = 1024*1024*10;//10M
File f = getUpLoadFile("UploadFile") ;
if(f.exists()){
System.out.println("文件存在");
System.out.println("文件大小为:"+f.length()/1024+"KB");
long aaa= 1024;
if(f.length()/1024>=aaa){
throw new CsiiInputException("文件大小不能超过1M");
}
} else{
try {
f.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
}
System.out.println("文件不存在");
throw new CsiiInputException("文件不存在,请选择要上传的文件");
}
File upFile = getUpLoadFile("UploadFile");
byte fileByte[] = new byte[Integer.parseInt(Long.toString(upFile.length()))];
/* 判断文件类型*/
String fileProper = upFile.getName().substring(upFile.getName().lastIndexOf("."));
System.err.println("fileProper" + fileProper);
IndexedData resultD = new IndexedData();
try {
if (fileProper.equals(".rar")) {
/* 解析excle */
System.err.println("fileProper" + fileProper);
}
else {
throw new CsiiInputException("上传文件格式不对,请检查是否为rar文件");
}
}
catch (Exception e) {
throw new CsiiInputException("文件只能上传(.rar)格式文件,请检查上传文件");
}
}
/**
* 得到上传后存放在本地的文件名。
*/
protected java.io.File getUpLoadFile(String name) {
return MultipartUtil.getUpLoadFile(getParameterValues(name));
}
/**
* 根据Multipart返回的内容得到在server上存储的相应的文件。
* @return java.io.File
* @param values java.lang.String[]
*/
public static java.io.File getUpLoadFile(String[] values) {
File file = null;
if ( values != null && values.length == 5 ) {
if ( values[0].equals("MultiPartFile") ) {
StringBuffer filename = new StringBuffer(values[1]); // values[1] is the directory name.
filename.append(File.separator);
filename.append(values[3]); // values[3] is the digest.
filename.append(values[2]); // values[2] is the file name.
file = new File(filename.toString());
}
}
return file;
- 上传文件 JSP+java
- 文件上传 java jsp
- java jsp 实现文件上传
- JSP/Java/Struts实现文件上传
- Java / JSP 文件上传与下载
- JSP 进行文件上传。JSP文件上传
- Java.Web - JSP文件上传,Servlet接收文件
- jsp文件上传与java文件保存到tomcat
- jsp文件上传
- jsp文件上传
- jsp文件上传处理
- jsp实现文件上传
- jsp上传文件
- JSP mySmartUpload上传文件
- JSP Uploader上传文件
- jsp上传文件
- 文件上传(JSP)
- 使用jsp上传文件
- acl-控制列表编辑
- 在Linux下安装和使用MySQL
- 绘制平行线
- 我对【纹理颜色混合】与【ALPHA混合】的理解
- 经典对白,超然人生
- 上传文件 JSP+java
- C#通过Win32 API操作IE浏览器 --- 获得IE的URL
- DataGrid数据导出excel文件,有时出现乱码解决方法。
- java日期函数2
- 北京拟严控“双外生”进京 近九成青年表示反对
- 高效能人士的9种性格(转载)
- 关于字符串逆序的问题
- 开放封闭原则--OCP
- 进制转换(一)