Check to run only once a day and when Internet is connected


I have a java code that must save an image from a URL, once a day. I want to put the executable jar file in windows startup folder to run every time the windows starts and when connects to internet; but, the windows may be start more than one time every day. So, I want my code checks if has been ran and saved the image today, it don’t run again (the name of saved image is Wallpaper and i don't want to change its name). How can I do this? Thank you.

public static void main(String[] args) throws Exception {
    String imageUrl ="";

    String destinationFile = "E:\\Picture\\Wallpaper.jpg";

    saveImage(imageUrl, destinationFile);

public static void saveImage(String imageUrl, String destinationFile) throws IOException {
    URL url = new URL(imageUrl);

    byte[] b = new byte[2048];
    int length;

    try {
        InputStream is=url.openStream();
            OutputStream os = new FileOutputStream(destinationFile);
            while ((length = != -1) {
                os.write(b, 0, length);
    }catch (UnknownHostException e){

You could download the image only if the current time is greater than 24 hours after the last modification time of the destination file.