上传文件

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();

posted @ 2012-06-21 20:28  java程序员-c  阅读(111)  评论(0编辑  收藏  举报