如何在不打开浏览器的情况下在指定目录的url内容中下载文件?

编程入门 行业动态 更新时间:2024-10-06 22:32:38
本文介绍了如何在不打开浏览器的情况下在指定目录的url内容中下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

import java.MalformedURLException; import java.URL; import java.security.cert.Certificate; import java.io.*; import javax.ssl.HttpsURLConnection; import javax.ssl.SSLPeerUnverifiedException; public class HttpsClient{ public static void main(String[] args) { new HttpsClient().testIt(); } private void testIt(){ String https_url = "www.google/"; URL url; try { url = new URL(https_url); HttpsURLConnection con = (HttpsURLConnection)url.openConnection(); //dumpl all cert info print_https_cert(con); //dump all the content print_content(con); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } private void print_https_cert(HttpsURLConnection con){ if(con!=null){ try { System.out.println("Response Code : " + con.getResponseCode()); System.out.println("Cipher Suite : " + con.getCipherSuite()); System.out.println("\n"); Certificate[] certs = con.getServerCertificates(); for(Certificate cert : certs){ System.out.println("Cert Type : " + cert.getType()); System.out.println("Cert Hash Code : " + cert.hashCode()); System.out.println("Cert Public Key Algorithm : " + cert.getPublicKey().getAlgorithm()); System.out.println("Cert Public Key Format : " + cert.getPublicKey().getFormat()); System.out.println("\n"); } } catch (SSLPeerUnverifiedException e) { e.printStackTrace(); } catch (IOException e){ e.printStackTrace(); } } } private void print_content(HttpsURLConnection con){ if(con!=null){ try { System.out.println("****** Content of the URL ********"); BufferedReader br = new BufferedReader( new InputStreamReader(con.getInputStream())); String input; while ((input = br.readLine()) != null){ System.out.println(input); } br.close(); } catch (IOException e) { e.printStackTrace(); } } } }

此代码只执行内容....但我希望下载的URL文件在我指定的目录中.... 任何人都可以请我这个....

this code is just executing only the content.... but i want the downloaded URL file in my specified directory.... can anybody please me for that....

推荐答案

你有两个问题,你需要改变 String https_url =www.google/;指向你的文件 和 print_content例程因为这只显示在控制台上。 /> 谷歌有很多例子,这样的东西可能符合你的要求 从网上下载 [ ^ ] 问候 / Darren You have two issues, you will need to change String https_url = "www.google/"; to point to your file and print_content routine because this only displays to the console. Google has many examples and something like this may fit your requirements download from the web[^] Regards /Darren

更多推荐

如何在不打开浏览器的情况下在指定目录的url内容中下载文件?

本文发布于:2023-11-12 21:15:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582542.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:情况下   打开浏览器   文件   目录   内容

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!