根据服务器url地址下载文件

    public static void downLoad(String _url) throws IOException,FileNotFoundException
    {
         URL url = new URL(_url);
             HttpURLConnection connection =(HttpURLConnection)url.openConnection();
             DataInputStream in = new DataInputStream(connection.getInputStream());
             String name = FileUtil.getUrlFileName(_url);
             log.info("url 的文件名为:"+name);
             String newName =                            Properties.getString("HTML2PDF_Pilot_path")+"/temp/"+name+".doc";
             log.info("本地文件路径为:"+newName);
             DataOutputStream out=new DataOutputStream(new FileOutputStream(newName));
             byte[] buffer = new byte[4096];
             int count = 0;
             while ((count = in.read(buffer)) > 0) {
                 out.write(buffer, 0, count);
             }
             out.close();
             in.close();
    }

你可能感兴趣的:(根据服务器url地址下载文件)