Chinaunix首页 | 论坛 | 博客
  • 博客访问: 573980
  • 博文数量: 98
  • 博客积分: 4045
  • 博客等级: 上校
  • 技术积分: 1157
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-31 16:56
文章分类

全部博文(98)

文章存档

2010年(7)

2009年(15)

2007年(73)

2006年(3)

我的朋友

分类: Java

2007-06-08 14:02:50


import org.apache.struts.upload.FormFile;
    
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileOutputStream;
    
/*
 * 文件上传类!
 */

    
public class Upload {
    /**
     * @param path 要存储的路径
     * @param file 文件
     * @return
     */

    public boolean up(String path, FormFile file)throws Exception {
        InputStream in = null;
        OutputStream out = null;
        try {
            in = file.getInputStream();
            out = new FileOutputStream(path);
            int read = 0;
            byte[] buffer = new byte[8192];
    
            while ((read = in.read(buffer, 0, 8192)) != -1) {
                out.write(buffer, 0, read);
            }
            out.close();
            in.close();
            return true;
        } catch (Exception e) {
            file.destroy();
            e.printStackTrace();
            return false;
        }
    }
    
}

阅读(2183) | 评论(1) | 转发(0) |
0

上一篇:java内嵌浏览器源码

下一篇:正则表达式1

给主人留下些什么吧!~~

chinaunix网友2008-12-04 21:44:19

,