如何使用 Java 和 Jersey 存储下载的文件?
我使用 Jersey 来构建 RESTful 服务,目前我陷入了一些我认为应该不会太难的事情上。
我设法获取我想要下载的文件,但我不知道如何保存它。
我在网上搜索答案,但没有找到任何有用的内容足以填补我的知识空白。
您能否告诉我如何继续将文件保存在硬盘上的某个位置?任何代码示例都将受到高度赞赏!
Client client = Client.create();
WebResource imageRetrievalResource = client
.resource("http://server/");
WebResource wr=imageRetrievalResource.path("instances/attachment");
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("item", "1");
Builder wb=wr.accept("application/json,text/html,application/xhtml+xml,application/xml");
client.addFilter(new HTTPBasicAuthFilter("user","pass"));
ClientResponse response= wr.queryParams(queryParams).get(ClientResponse.class);
String s= response.getEntity(String.class);
System.out.println(response.getStatus());
谢谢你!
I use Jersey for building RESTful services and currently I'm stuck on something that, I thought, shouldn't be too hard.
I manage to GET the file I want to download, but I do not know how to save it.
I searched for answers on the web, but I didn't find anything useful enough to fill in the gaps in my knowledge.
Can you, please, give me a hit how to go on in order to save the file in a location on hdd? Any code samples are going to be highly appreciated!
Client client = Client.create();
WebResource imageRetrievalResource = client
.resource("http://server/");
WebResource wr=imageRetrievalResource.path("instances/attachment");
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("item", "1");
Builder wb=wr.accept("application/json,text/html,application/xhtml+xml,application/xml");
client.addFilter(new HTTPBasicAuthFilter("user","pass"));
ClientResponse response= wr.queryParams(queryParams).get(ClientResponse.class);
String s= response.getEntity(String.class);
System.out.println(response.getStatus());
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我得到了我的问题的答案:
I got the answer to my question:
使用 Rest easy Client 这就是我所做的。
Using Rest easy Client this is what I did.