下载服务器上的文件—通过url

String fileHome = this.getServlet().getServletContext().getRealPath("/");


  InputStream is;


  FileOutputStream fileOut = new FileOutputStream(fileHome + "upload/receive/" + md.getId()+1 + ".zip");


  URL url = new URL(md.getFromIp().replace("receive/onlineExport.do", "upload/receive/" + md.getId() + ".zip"));


  URLConnection c = url.openConnection(); // *


  c.connect();


  is = c.getInputStream();


  int data;


  while ((data = is.read()) != -1) {


   fileOut.write(data);


  }


  is.close();


  fileOut.close();

你可能感兴趣的:(下载服务器上的文件—通过url)