现在的位置: 首页 > 综合 > 正文

上传文件

2013年01月07日 ⁄ 综合 ⁄ 共 640字 ⁄ 字号 评论关闭

String filePath = "c:/";
  String fileName = request.getParameter("title");
        InputStream inputStream =request.getInputStream();
        FileOutputStream outputStream = new FileOutputStream(new File(filePath+fileName+".png"));
       
  //int formlength = request.getContentLength();
  int formlength = Integer.parseInt(request.getParameter("file"));
  byte[] formcontent = new byte[formlength];
  int totalread = 0;
  int nowread = 0;
  while (totalread < formlength) {
   nowread = inputStream.read(formcontent, totalread, formlength);
   totalread += nowread;
  }

        outputStream.write(formcontent);
        outputStream.flush();
        outputStream.close();
        inputStream.close();

抱歉!评论已关闭.