String url = "https://www.example.com"; File file = new File("example.html"); try { FileUtils.copyURLToFile(new URL(url), file); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
String imageUrl = "https://www.example.com/image.png"; File imageFile = new File("image.png"); try { FileUtils.copyURLToFile(new URL(imageUrl), imageFile); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }In this example, we create a new File object for 'image.png' and then use FileUtils.copyURLToFile to copy the image from 'https://www.example.com/image.png' to the file. The package library for this code is 'org.apache.commons.io'.