1.以流的方式下载.
public HttpServletResponse download(String path, HttpServletResponse response) {
try {
// path是指欲下载的文件的路径。
File file = new File(path);
// 取得文件名。
String filename = file.getName();
// 取得文件的后缀名。
String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();
</span><span style="color: #008000;">//</span><span style="color: #008000;"> 以流的形式下载文件。</span>
InputStream fis = <span style="color: #0000ff;">new</span> BufferedInputStream(<span style="color: #0000ff;">new</span><span style="color: #000000;"> FileInputStream(path));
</span><span style="color: #0000ff;">byte</span>[] buffer = <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">byte</span><span style="color: #000000;">[fis.available()];
fis.read(buffer);
fis.close();
</span><span style="color: #008000;">//</span><span style="color: #008000;"> 清空response</span>