日期:2014-05-20 浏览次数:20734 次
//得到文件?名 String filename=file.getOriginalFilename(); 25. if(file.getSize()>0){ try { SaveFileFromInputStream(file.getInputStream(),"D:/",filename); } catch (IOException e) { System.out.println(e.getMessage()); return null; } }else{ throw new Exception("上传失败:上传文件不能为?空"); } public void SaveFileFromInputStream(InputStream stream,String path,String filename) throws IOException { FileOutputStream fs=new FileOutputStream( path + "/"+ filename); byte[] buffer =new byte[1024*1024]; int bytesum = 0; int byteread = 0; while ((byteread=stream.read(buffer))!=-1){ bytesum+=byteread; fs.write(buffer,0,byteread); fs.flush(); } fs.close(); stream.close(); }