Menu

Downloading files with Utils.java

AntifreeZZe

A basic asynchronous method to download files

import javax.swing.JOptionPane; //For message boxes
import net.Utils;

public static void Main(){

    Thread t = new Thread(new Runnable(){
        public void run(){
            try{
                Utils.Download("path/to/local/file","http://example.com/file.txt");
            }catch(Exception e){
                JOptionPane.showMessageDialog(null,e.getMessage());
            }
        }
    }, "download");

    Thread d = new Thread(new Runnable(){
        public void run(){
            try{
                while(Utils.locked){
                    /*Update your values*/
                    Thread.sleep(1); //Sleep for second
                }
            }catch(Exception e){
                JOptionPane.showMessageDialog(null,e.getMessage());
            }
        }
    },"update");
    t.start();
    d.start();

}