title: Best way to design Java file download manager
body: <p>I would like to write simple Java downloader for my backup website. What is important, applet should be able to download many files at once.</p>
  
  <p>So, here is my problem. Such applet seems to me easily to hack or infect. What is more, it for sure will need many system resources to run. So, I would like to hear your opinions what is the best, the most optimal and the most secure way to do it.</p>
  
  <p>I thought about something like this:</p>
  
  <pre><code>//user chose directory to download his files
  //fc is a FileChooser
  //fc.showSaveDialog(this)==JFileChooser.APPROVE_OPTION
  try {
      for(i=0;i&lt;=urls.length-1;i++){
  
           String fileName = '...';//obtaining filename and extension
  
           fileName=fileName.replaceAll(" ", "_");
           //I am not sure if line above resolves all problems with names of files...
  
           String path = file.getAbsolutePath() + File.separator + fileName;
  
           try{
                InputStream is=null;
                FileOutputStream os=new FileOutputStream(path);
                URLConnection uc = urls[i].openConnection();
                is = uc.getInputStream();
  
                int a=is.read();
                while(a!=-1){
                    os.write(a);
                    a=is.read();
                }
                is.close();
                os.close();
           }
           catch(InterruptedIOException iioe) {
                //TODO User cancelled.
           }
           catch(IOException ioe){
                //TODO
           }
       }
  }
  </code></pre>
  
  <p>but I am sure that there is a better solution.</p>
  
  <p>There is one more thing - when user wants to download really huge amount of files (e.g. 1000, between 10MB and 1GB), there will be several problems. So, I thought about setting a limit for it, but I don't really know how to decide how many files at once is OK. Should I check user's Internet connection or computer's load?</p>
  
  <p>Thanks in advance</p>
  
  <p>BroMan</p>