(1)解决方式
public static File getTempFile(HttpServletRequest request, String name){ try { Part part = request.getPart("file"); InputStream is = part.getInputStream(); FileOutputStream fos = new FileOutputStream(getRequest().getRealPath("/") + name); byte[]buff=new byte[1024]; int len=0; while((len=is.read(buff))>0){ fos.write(buff); } is.close(); fos.close(); File fileTemp = new File(getRequest().getRealPath("/") + name); return fileTemp; } catch(Exception e) { System.err.println("上传文件错误:"+e); } return null; }
时间: 2025-01-04 08:35:31