日期:2014-05-18  浏览次数:20685 次

怎么下载文件夹下的文件

d:\work   下是word   或excel文件
问题是:用jsp怎么做一个页面,把d:\work下
的文件都列出来,点击其中一个
会弹出打开还是另存为的对话框?


------解决方案--------------------
filename=new String(filename.getBytes( "iso8859-1 "), "gb2312 ");
response.setContentType( "application/x-msdownload ");
response.setHeader( "Content-disposition ", "attachment; "+ "filename= "+ new String(filename.getBytes( "gb2312 "), "iso8859-1 "));
//String filepath = "D:\\Apache Software Foundation\\Tomcat 5.5\\webapps\\webModule\\tempdb\\ ";
bis =new java.io.BufferedInputStream(new java.io.FileInputStream(config.getServletContext().getRealPath( "tempdb/ "+filename)));
bos=new java.io.BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
{
bos.write(buff,0,bytesRead);
}
bis.close();
bos.close();
File f=new File(config.getServletContext().getRealPath( "tempdb/ "+filename));
f.delete();

}
catch (SQLException ex) {
ex.printStackTrace();
}


看看这个 http://www.haolla.com/girls/index.asp
http://haolla.com/wy
------解决方案--------------------
帮忙顶。
File f=new File();可以列出文件。
下载文件,就用其它组件,比如jspsmartupload等。
------解决方案--------------------
File dir = new File( "d:/work ");
String[] fs = dir.list();
for (int i = 0; i < fs.length; i++) {
if (fs[i].indexOf( ". ") != -1)
System.out.println(fs[i]);

}
然后在页面把fs[i]做个超链就行了
------解决方案--------------------
直接用本地文件的方式来下载安全性方面不大好,还是不推荐使用的
------解决方案--------------------
哥们,我也是这个问题!