Skip to content

Instantly share code, notes, and snippets.

@ashikuzzaman-ar
Last active November 10, 2017 21:07
Show Gist options
  • Save ashikuzzaman-ar/50a8aee9eaf86424c358c7121f52fe93 to your computer and use it in GitHub Desktop.
Save ashikuzzaman-ar/50a8aee9eaf86424c358c7121f52fe93 to your computer and use it in GitHub Desktop.
Downloading a file from internate
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) {
String from = "https://download.gimp.org/mirror/pub/gimp/v2.8/gimp-2.8.10.tar.bz2";
String to = "/home/ashik/gimp-2.8.10.tar.bz2";
try {
System.out.println("Starting!");
InputStream stream = new URL(from).openStream();
new Thread(new Runnable() {
@Override
public void run() {
int timeCounter = 0;
while (true) {
try {
System.out.println("Time : " + timeCounter++);
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();
Files.copy(stream, Paths.get(to));
System.out.println("Finished!");
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment