200分求文件下载,该如何解决

200分求文件下载
servlet中如何实现文件下载?求大神给代码参考200分求文件下载,该如何解决
由于我最大只能给100分,所以我发了两次
请到 http://bbs.****.net/topics/390893604 评论

------解决思路----------------------
http://blog.****.net/jimesum1/article/details/2203315
------解决思路----------------------
http://www.blogjava.net/fastunit/archive/2008/01/22/177034.html


这种网上多的是案例,楼主搜一下就知道的
------解决思路----------------------
引用:
Quote: 引用:

http://www.blogjava.net/fastunit/archive/2008/01/22/177034.html
这种网上多的是案例,楼主搜一下就知道的


网上是有很多 但注释得很不清除



你是需要每一句代码都要注释么?  其实没必要,你可以先照着案例写一个试试,功能实现了,再去分析怎么实现的
------解决思路----------------------
最近刚实现了一个文件上传的公用类,分享给楼主!
一个两个类文件,一个是文件上传的属性类(FileProperty.java)和上传实现类(FileUnloadUtil.java)。
代码如下:
属性类(FileProperty.java)
package upload;

import java.util.Date;

public class FileProperty {
private String name;  
    private String type;  
    private String contentType;  
    private float size;  
    private Date uploadTime;  
      
    public FileProperty() {  
        super();  
    }  

    public FileProperty(String name, String type, String contentType, float size, Date uploadTime) {  
        super();  
        this.name = name;  
        this.type = type;  
        this.contentType = contentType;  
        this.size = size;  
        this.uploadTime = uploadTime;  
    }  

    public String getName() {  
        return name;  
    }  

    public void setName(String name) {  
        this.name = name;  
    }  

    public float getSize() {  
        return size;  
    }  

    public void setSize(float size) {  
        this.size = size;  
    }  

    public String getType() {  
        return type;  
    }  

    public void setType(String type) {  
        this.type = type;  
    }  
      
    public String getContentType() {  
        return contentType;  
    }  

    public void setContentType(String contentType) {  
        this.contentType = contentType;  
    }  

    public Date getUploadTime() {  
        return uploadTime;  
    }  

    public void setUploadTime(Date uploadTime) {  
        this.uploadTime = uploadTime;  
    }  
}


实现类另一个帖子见!
------解决思路----------------------
response.setContentType("application/octet-stream");
response.setHeader("content-Disposition", "attachment;filename='要上传的文件.txt'");
ServletOutputStream out = response.getOutputStream();
File file = new File("f:\\要下传的文件.txt");
FileInputStream in = new FileInputStream(file);
byte[] ino = new byte[1024];
while(in.read(ino) != -1 ){
out.write(ino);
}
in.close();
ino.clone();