首页 > 技术文章 > java文件下载 rest

guochunyi 2016-06-13 14:39 原文

/**
     * 返回文件二进制
     * 
     */
    @GET
    @Path("/excel")
    @Produces("application/vnd.ms-excel; charset=UTF-8")
    @ModuleSecurityAuth(moduleId=ModuleId.MONITOR_REPORT ,privilegeOperation=PrivilegeOperation.READ)
    public Response download(final @QueryParam("path") String path) throws IOException {
        File file = new File("/macc/excel/"+path);
    //解决文件名乱码

      String pathTmp = java.net.URLEncoder.encode(path, "UTF-8");


         
        ResponseBuilder response = Response.ok((Object) file);
        String header = "attachment; filename=" + pathTmp;
        response.header("Content-Disposition",
                header);
        return response.build();
    }

 

推荐阅读