How to create a FileHostObject from a url?

34 views Asked by At

I have a URL of an image as a String.

String url = "http://blog.room34.com/wp-content/uploads/underdog/logo.thumbnail.png"

I want create a FileHostOject from that. (org.jaggeryjs.hostobjects.file.FileHostObject).

Can anyone tell me how can I achieve that?

1

There are 1 answers

1
Peter Pan On

You can use java lib "Apache Commons IO" to do it:

My Simple Code:

URL url = new URL(
    "http://blog.room34.com/wp-content/uploads/underdog/logo.thumbnail.png");
InputStream input = url.openStream();
String png = "sample.png";
FileOutputStream output = new FileOutputStream(png);
IOUtils.copy(input, output);

Class "IOUtils" is a common tool for IO stream operation in commons-io jar.