随笔-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 阅读(5627) 评论(2)  编辑  收藏 所属分类: 每日积累

评论:
# re: html:file标签的使用 2012-03-21 10:37 | 宿舍
地方  回复  更多评论
  
# re: html:file标签的使用[未登录] 2013-11-12 21:20 | 1
update 哪里来的??  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: