public class FileUtil { /** * Get remote files * @param remoteFilePath remote file path * @param localFilePath local file path */ public void getFile(String remoteFilePath,String localFilePath){ URL urlfile = null; HttpURLConnection httpUrl = null; BufferedInputStream bis = null; BufferedOutputStream bos = null; File f = new File(localFilePath); /* //If you need to set the proxy String proxy = "192.168.224.12"; String port = "8080"; Properties systemProperties = System.getProperties(); systemProperties.setProperty("http.proxyHost",proxy); systemProperties.setProperty("http.proxyPort",port);*/ try{ urlfile = new URL(remoteFilePath); httpUrl = (HttpURLConnection)urlfile.openConnection(); httpUrl.connect(); bis = new BufferedInputStream(httpUrl.getInputStream()); bos = new BufferedOutputStream(new FileOutputStream(f)); int len = 2048; byte [] b = new byte [len]; while((len=bis.read(b))!=-1) { bos.write(b, 0, len); } bos.flush(); bis.close(); httpUrl.disconnect(); System.out.println("done~"); }catch(Exception e){ } } }