目测是长度计算有问题,哎,最近不想看代码,头痛~贴一段上传文件的代码,看对你有用没~ [mw_shl_code=java,true]private void upLoadFile(){ try{ FileInputStream in = new FileInputStream(telsfile); //获取当前项目的根目录 String path = ServletActionContext.getServletContext().getRealPath("/"); //构造新的文件名 String fileName = UUID.randomUUID().toString()+telsfileFileName.substring(telsfileFileName.indexOf(".")); //新的路径 String newFilePath =path+ "upload" + "\\"+fileName; System.out.println(newFilePath); //判定文件夹路径是否存在 File file = new File(path+"upload"+"\\"); if(!file.exists()){ file.mkdirs(); } FileOutputStream out = new FileOutputStream(newFilePath); int len ; while((len =in.available())!= 0){ byte[] buf ; if(len > 1024)buf= new byte[1024]; else buf = new byte[len]; in.read(buf); out.write(buf); } ServletActionContext.getRequest().setAttribute("filepath",fileName); out.close(); in.close(); }catch(Exception e){ e.printStackTrace(); } }[/mw_shl_code]