kar*_*rla 5 java download 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());
Run Code Online (Sandbox Code Playgroud)
谢谢!
kar*_*rla 10
我得到了我的问题的答案:
File s= response.getEntity(File.class);
File ff = new File("C:\\somewhere\\some.txt");
s.renameTo(ff);
FileWriter fr = new FileWriter(s);
fr.flush();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5615 次 |
| 最近记录: |