FileServices.java 文件源码

java
阅读 17 收藏 0 点赞 0 评论 0

项目:step 作者:
@GET
@Secured
   @Path("/{id}")
public Response downloadFile(@PathParam("id") String id) {
    File file = attachmentManager.getFileById(id);

    StreamingOutput fileStream = new StreamingOutput() {
        @Override
        public void write(java.io.OutputStream output) throws IOException {
            java.nio.file.Path path = file.toPath();
            byte[] data = Files.readAllBytes(path);
            output.write(data);
            output.flush();
        }
    };
    return Response.ok(fileStream, MediaType.APPLICATION_OCTET_STREAM)
            .header("content-disposition", "attachment; filename = "+file.getName()).build();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号