import org.apache.commons.io.IOUtils; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Example { public static void main(String[] args) { try { FileInputStream input = new FileInputStream("input.txt"); FileOutputStream output = new FileOutputStream("output.txt"); IOUtils.copy(input, output); input.close(); output.close(); } catch (IOException e) { e.printStackTrace(); } } }
import org.apache.commons.io.IOUtils; import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; import java.net.URLConnection; public class Example { public static void main(String[] args) { try { URL url = new URL("http://example.com"); URLConnection connection = url.openConnection(); IOUtils.copy(connection.getInputStream(), new FileOutputStream("output.txt")); } catch (IOException e) { e.printStackTrace(); } } }In this example, a URL object is created to represent a URL of a website. A URLConnection object is created to establish a connection to the website. The IOUtils.copy() method is used to copy the content from the website input stream to the file output stream.