Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void download(final String host, final String fileName)
- {
- new Thread(new Runnable() {
- public void run() {
- Windows.progressBar.setValue(0);
- try
- {
- URL url = new URL(host);
- URLConnection connexion = url.openConnection();
- FileOutputStream writeFile = null;
- writeFile = new FileOutputStream(fileName);
- InputStream input = connexion.getInputStream();
- byte[] buffer = new byte[1024];
- int read;
- long readed = 0;
- int total = connexion.getContentLength();
- while ((read = input.read(buffer)) > 0) /* Téléchargement */
- {
- readed += read;
- Windows.progressBar.setValue((int) (100 * readed / total));
- Windows.telechargement.setText((int) (100 * readed / total) + "%");
- Windows.contentPane.validate();
- writeFile.write(buffer, 0, read);
- System.out.println((int) (100 * readed / total) + "%");
- }
- input.close();
- writeFile.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }).start();
- while(Windows.progressBar.getValue() < 100)
- {
- System.out.println("");
- }
- }
Add Comment
Please, Sign In to add comment