Apache Commons IO to download website content from URI using IOUtils
Tags: Apache Commons Apache Commons IO
Java Code Examples for org.apache.commons.io.IOUtils.toString()
Below Java code example to show you how to use Apache Commons IO IOUtils class to download website content from java.net.URI.
package simplesolution.dev;
import org.apache.commons.codec.Charsets;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class IOUtilToStringFromURIExample {
public static void main(String... args) {
try {
URI uri = new URI("https://simplesolution.dev/");
String content = IOUtils.toString(uri, Charsets.UTF_8);
System.out.println(content);
} catch (URISyntaxException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Happy Coding 😊