How do you Programmatically Download a Webpage in Java

前端 未结 11 2245
无人共我
无人共我 2020-11-22 11:20

I would like to be able to fetch a web page\'s html and save it to a String, so I can do some processing on it. Also, how could I handle various types of compr

11条回答
  •  梦谈多话
    2020-11-22 11:50

    To do so using NIO.2 powerful Files.copy(InputStream in, Path target):

    URL url = new URL( "http://download.me/" );
    Files.copy( url.openStream(), Paths.get("downloaded.html" ) );
    

提交回复
热议问题