67,512
社区成员
发帖
与我相关
我的任务
分享
public String createEmployeeInco(){
try{
if(file != null){
employee = employeeManager.getEmployee(user_id) ;
String suffix = this.fileFileName.substring(this.getFileFileName().lastIndexOf(".")+1) ; // 文件后缀名
String filepath = ServletActionContext.getServletContext().getRealPath("/user_inco/") + File.separator + employee.getUserNo() + "." + suffix ;
boolean flag = FileUtil.saveFile(file, filepath) ;
if(flag){
employee.setPath("/user_inco/"+employee.getUserNo() + "." + suffix ) ;
} else {
FileUtil.delFile("/user_inco/"+employee.getPath()) ;
}
employeeManager.editEmployee(employee) ;
tag = "2" ;
}
} catch (Exception e) {
e.printStackTrace() ;
}
return SUCCESS ;
}
public static boolean saveFile(File file,String filepath) throws FileNotFoundException{
File outFile = new File(filepath) ;
if(!outFile.getParentFile().exists()){
outFile.getParentFile().mkdirs() ;
}
InputStream inputStream = null ;
OutputStream outputStream = null ;
try{
inputStream = new FileInputStream(file) ;
outputStream = new FileOutputStream(outFile) ;
byte[] b = new byte[1024] ;
int temp = 0 ;
while ((temp = inputStream.read()) != -1) {
outputStream.write(b,0,temp) ;
}
inputStream.close() ;
outputStream.close() ;
return true ;
} catch (Exception e) {
e.printStackTrace() ;
}
return false ;
}