我不知道是否让Jersey让您简单地回应一个文件,就像这里一样:
File download = new File("C://Data/Test/downloaded/empty.pdf");ResponseBuilder response = Response.ok((Object)download);你 可以 肯定使用StreamingOutput响应从服务器发送的文件,就像这样:
StreamingOutput stream = new StreamingOutput() { @Override public void write(OutputStream os) throws IOException, WebApplicationException { Writer writer = new BufferedWriter(new OutputStreamWriter(os)); //@TODO read the file here and write to the writer writer.flush(); }};return Response.ok(stream).build();并且您的客户希望读取流并将其放入文件中:
InputStream in = response.getEntityInputStream();if (in != null) { File f = new File("C://Data/test/downloaded/testnew.pdf"); //@TODO copy the in stream to the file f System.out.println("Result size:" + f.length() + " written to " + f.getPath());}


