当前位置: 代码迷 >> J2EE >> 文件上传完成不能查看解决思路
  详细解决方案

文件上传完成不能查看解决思路

热度:63   发布时间:2016-04-17 23:08:27.0
文件上传完成不能查看

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 ;
}


求大神给看看,我这个方法上传文件,融合SSH2的,本来只是一个762K的图片上传完成后变成69.4M而且也不能查看了。请问这是什么问题
------解决思路----------------------
没把你点透 以为你看了会明白。

说白了,你read方法能把 内容读到 b里么?  你仔细看看api文档
  相关解决方案