Created
May 16, 2014 19:31
-
-
Save vladholubiev/eae0c9990179052f5e8f to your computer and use it in GitHub Desktop.
Downloads current image of Rivne webcam every 6 seconds.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.imageio.ImageIO; | |
import java.awt.image.BufferedImage; | |
import java.io.File; | |
import java.io.IOException; | |
import java.net.URL; | |
import java.util.Timer; | |
import java.util.TimerTask; | |
public class ImageDownloader extends Timer { | |
public static void main(String[] args) { | |
int delay = 0; | |
int period = 6000; | |
Timer timer = new Timer(); | |
timer.scheduleAtFixedRate(new TimerTask() { | |
public void run() { | |
BufferedImage image = null; | |
try { | |
URL url = new URL("http://91.237.244.6/files/image.jpg"); | |
image = ImageIO.read(url); | |
long unixTime = System.currentTimeMillis() / 1000L; | |
System.out.println(unixTime); | |
ImageIO.write(image, "jpg", new File("E:\\" + unixTime + ".jpg")); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
}, delay, period); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment