隨筆-51  評論-14  文章-0  trackbacks-0
                  FormFile upfile = update.getUpfile();


                  String realPath 
          = getServlet().getServletContext().getRealPath("/");

                  
          //        String realPath = request.getRealPath("");

                  
                  String filepath 
          = realPath+"/upfile";
                  String filename 
          = upfile.getFileName();
                  
          int filesize = upfile.getFileSize();
                  File file
          =new File(filepath,filename);
                  
          byte a[] = new byte[filesize];
                  
          try {
                      InputStream in 
          = upfile.getInputStream();
                      
          int read=0;                 //實際讀出的文件長度
                      int allread=0;               //共讀出的文件長度
                      while(allread<filesize){
                          read
          =in.read(a,allread,filesize);
                          allread
          +=read;
                      }
                      FileOutputStream out
          =new FileOutputStream(file);
                      out.write(a);
                      in.close();
                      out.close();
                      
                  } 
          catch (FileNotFoundException e) {
                      
          // TODO Auto-generated catch block
                      e.printStackTrace();
                  } 
          catch (IOException e) {
                      
          // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
          posted on 2008-07-29 10:04 Hank1026 閱讀(5657) 評論(2)  編輯  收藏 所屬分類: 每日積累

          評論:
          # re: html:file標簽的使用 2012-03-21 10:37 | 宿舍
          地方  回復  更多評論
            
          # re: html:file標簽的使用[未登錄] 2013-11-12 21:20 | 1
          update 哪里來的??  回復  更多評論
            
          主站蜘蛛池模板: 昭平县| 祁门县| 鹰潭市| 年辖:市辖区| 千阳县| 永修县| 宿迁市| 华亭县| 松原市| 道孚县| 内江市| 柘荣县| 中山市| 紫云| 内乡县| 左贡县| 沧源| 陵川县| 惠安县| 顺昌县| 大悟县| 夏邑县| 若尔盖县| 喀喇| 富平县| 龙里县| 衡南县| 昆山市| 邢台县| 娱乐| 达孜县| 高邮市| 崇礼县| 花莲县| 兴文县| 凉山| 法库县| 固阳县| 江永县| 兴海县| 尤溪县|