public InputStream getDownloadFile() throws Exception { // 获取指定目录的文件 InputStream is = new FileInputStream(file.getFilePath()); // 获取服务位置的文件 // InputStream is=ServletActionContext.getServletContext().getResourceAsStream(); return is; }
public boolean getFile(FileDownloadTools fdt, String[] ids) throws Exception { try { if (fdt.get(ids)) { getServletResponse().setHeader("charset", "ISO8859-1"); if (this.fileName == null) { this.fileName = fdt.getFileName(); } this.fileName = new String(this.fileName.getBytes(), "ISO8859-1"); // this.fileName = fdt.getFileName(); this.contentType = fdt.getContentType(); return true; } else { return false; } } catch (Exception e) { throw e; } }
public boolean getFile(FileDownloadTools fdt, String file, int width, int height) throws Exception { try { if (fdt.get(file)) { // 缩略图文件 File thumbFile = new File(fdt.getFilePath() + "_" + width + "_" + height + ".jpg"); try { // 如果缩略图不存在则生成 if (!thumbFile.exists()) { // 生成缩略图 Thumbnails.of(new File(fdt.getFilePath())) .size(width, height) .outputFormat("jpg") .toFile(thumbFile); } } catch (IOException e) { e.printStackTrace(); } fdt.setFilePath(thumbFile.getPath()); fdt.setFileName(width + "_" + height + "_" + fdt.getFileName()); getServletResponse().setHeader("charset", "ISO8859-1"); if (this.fileName == null) { this.fileName = fdt.getFileName(); } this.fileName = new String(this.fileName.getBytes(), "ISO8859-1"); // this.fileName = fdt.getFileName(); this.contentType = fdt.getContentType(); return true; } else { return false; } } catch (Exception e) { throw e; } }