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!
I got the answer to my question:
File s= response.getEntity(File.class);
File ff = new File("C:\\somewhere\\some.txt");
s.renameTo(ff);
FileWriter fr = new FileWriter(s);
fr.flush();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With