0
需要一個servlet從像/ home/Bureau這樣的路徑下載一個文件..在jee gwt 我用這個但是不工作 我去了下載所有文件的類型圖像需要一個servlet從像/ home /局的路徑下載文件
String filePath = request.getParameter("file");
String fileName = "test";
FileInputStream fileToDownload = new FileInputStream(filePath);
// ServletOutputStream output = response.getOutputStream();
response.setHeader("Content-Type", "image/png");
//response.setContentType("image/png");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".png\"");
// response.setContentLength(fileToDownload.available());
int readBytes = 0;
byte[] buffer = new byte[10000];
while ((readBytes = fileToDownload.read(buffer, 0, 10000)) != -1) {
//output.write(readBytes);
response.getOutputStream().write(readBytes);
}
response.getOutputStream().close();
fileToDownload.close();
fileToDownload.close();