日期:2014-05-18 浏览次数:20664 次
public boolean upload(List file,List fileName, String zlname,String zlnotes) throws DBException{
try{
String RESID = DateUtil.getNo();
// TODO
String filepath = Constant.CLOUD_FILEPATH;
SimpleDateFormat sdf1=new SimpleDateFormat("yyyyMMdd");
String ymd = sdf1.format(new Date());
filepath = filepath +"/" +ymd+"/"+zlname; //存放临时文件
File dir=new File(filepath);
if (dir.exists()==false){
dir.mkdirs();
}
for (int i = 0; i < file.size(); i++){
InputStream is = new FileInputStream(file.get(i).toString());
String name=fileName.get(i).toString();//得到上传文件的原名称
File destFile = new File(filepath, name);
OutputStream os = new FileOutputStream(destFile);
byte[] buffer = new byte[400];
int length = 0;
while ((length = is.read(buffer)) > 0){
os.write(buffer, 0, length);
}
is.close();
os.close();
}
System.out.println( filepath );
//压缩文件
Decompression.createZIP(filepath,filepath+""+RESID+".zip");
//删除文件
deleteFile(dir);
//TODO 存数据库
String sql = "INSERT INTO chl20 (RESID,RESNAME,RESDESC,RESURL,OPTIME) VALUES(?,?,?,?,?)";
Object[] args = new Object[] {RESID,zlname,zlnotes,"/"+ymd+"/"+zlname+""+RESID+".zip",new Date()};
this.baseJdbcDao.update(sql, args);
}catch (Throwable e) {
e.printStackTrace();
throw new DBException(e);
}
return true;
}