Download images from a web page in Netbeans

sams

New Member
I'm using Netbeans 7.2. Is there an API I can include in my project that will allow me to download a web page and images and store them locally?Edit:My current code is (Used from this link: How do you Programmatically Download a Webpage in Java)\[code\]public class WebpageGrabber {/** * @param args the command line arguments */public static void main(String[] args) { URL url; InputStream is = null; DataInputStream dis; String line; String fileName = "C:/Users/Me/Desktop/webpage.html"; WriteFile data = http://stackoverflow.com/questions/13712659/new WriteFile(fileName, true); try { url = new URL("http://stackoverflow.com/"); is = url.openStream(); // throws an IOException dis = new DataInputStream(new BufferedInputStream(is)); while ((line = dis.readLine()) != null) { System.out.println(line); data.WriteToFile(line); } } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { is.close(); } catch (IOException ioe) { // nothing to see here } }}}\[/code\]and I'm using this class to write the page to a file\[code\]public class WriteFile {String filePath;//String fileName = "website.html";boolean appendToFile;public WriteFile(String fPath){ filePath = fPath;}public WriteFile(String fPath, boolean appendValue){ filePath = fPath; appendToFile = appendValue;}public void WriteToFile(String textLine)throws IOException{ FileWriter write = new FileWriter(filePath, appendToFile); PrintWriter printLine = new PrintWriter(write); printLine.printf("%s" + "%n", textLine); printLine.close();}}\[/code\]This saves the webpage but the images have a rel attribute and reads them in from the website.
 
Back
Top