日期:2014-05-20 浏览次数:20695 次
FormFile file = myActionForm.getTheFile(); try { InputStream input = file.getInputStream(); String path = request.getRealPath("/"); System.out.println(path + "/" + file.getFileName()); // 文件路径及名称 ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream out = new FileOutputStream(path + "/" + file.getFileName()); //这里将输出名称改一下就行了,不一定要用file.getFileName(),可以用自定义的名字 int i = 0; byte[] buff = new byte[8192]; while ((i = input.read(buff, 0, 8192)) != -1) { out.write(buff, 0, i); } out.close(); input.close(); } catch (Exception ex) { System.out.println(ex.getMessage()); }
------解决方案--------------------
OutputStream out = new FileOutputStream(path + "/" + file.getFileName());