I have this code, and inside the 'saveImage()' function i explain in comments what my problem is. this code is meant to go to an image url and save that image to my desktop.
the main dilemma is I can't go directly to an image url (such as website.com/image.jpg)
I can get to a webpage that has multiple images on it, but need to single out a specific one.
import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; public class main { public static void main(String[] args) throws Exception { String numString = "WarCraft_"; String imageUrl = "http://sonsofthestorm.com/viewer.php?artist=raneman&cat=warcraft&art=1"; String destinationFile = "C:\\Users\\Turtle\\Desktop\\image.jpg"; saveImage(imageUrl, destinationFile); }//end main public static void saveImage(String imageUrl, String destinationFile) throws IOException { // somewhere around here, i need the program to look at this website url, (imageUrl) // find any images that start with the words: "WarCraft_" (numString) // and get that image, or set imageUrl to that image's url. URL url = new URL(imageUrl); InputStream is = url.openStream(); OutputStream os = new FileOutputStream(destinationFile); byte[] b = new byte[2048]; int length; while ((length = is.read(b)) != -1) { os.write(b, 0, length); } is.close(); os.close(); } }//end class