html:file标签的使用

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

你可能感兴趣的:(html)