Java客户端下载服务器端的文件
2009-02-26 17:55
337 查看
一个比较简单的Java客户端下载服务器端的文件的方法
// 下载服务器端的文件
private void save(String filePath, HttpServletResponse response)
throws FileNotFoundException, IOException {
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "attachment; filename=/""
+ "tempStore.xls" + "/"");
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
filePath));
BufferedOutputStream bos = new BufferedOutputStream(response
.getOutputStream());
try {
byte[] buff = new byte[2 * 1024];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} finally {
if (bis != null) {
bis.close();
}
if (bos != null) {
bos.close();
}
}
}
// 下载服务器端的文件
private void save(String filePath, HttpServletResponse response)
throws FileNotFoundException, IOException {
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "attachment; filename=/""
+ "tempStore.xls" + "/"");
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
filePath));
BufferedOutputStream bos = new BufferedOutputStream(response
.getOutputStream());
try {
byte[] buff = new byte[2 * 1024];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} finally {
if (bis != null) {
bis.close();
}
if (bos != null) {
bos.close();
}
}
}
相关文章推荐
- 为了在本机上测试,必须先安装memcache的服务器端,安装文件见附件,只能在Administrator用户下才能启动memcached服务。 首先要下载memcache的客户端java实现的jar
- VB.NET服务器端令客户端下载PDF文件
- (Android)JavaSocket编程,文件上传到服务器,客户端Android,服务器端J2SE
- (下载、打开)从服务器端将文件传送到客户端
- java客户端文件的上传和下载
- java方法客户端下载服务器上的文件到本地
- 【javaweb:servlet】客户端请求服务端进行文件下载的demonstration
- [Java Web]服务器获取远程文件并Zip打包给客户端下载
- Java NIO 服务器与客户端实现文件下载
- 批量下载图片文件(服务器端 和 客户端)
- java后台下载服务器端文件 下载其他系统文件
- [java]客户端从服务器下载文件
- Java下http下载文件客户端和上传文件客户端实例代码
- java方法客户端下载服务器上的文件到本地
- java Socket 客户端向服务器端发送流(不是文件),服务器端read出现阻塞问题
- C#将服务器端excel文件下载到客户端的简单方法
- 多线程文件下载的服务器端及客户端
- Android文件下载含服务器端(客户端 UI界面异步请求部分)三
- 在服务器端生成Excel文件后如何提供客户端下载 Response.Redirect()
- java方法客户端下载服务器上的文件到本地