How to download and save a file from Internet using Java?

前端 未结 21 2876
情深已故
情深已故 2020-11-21 05:06

There is an online file (such as http://www.example.com/information.asp) I need to grab and save to a directory. I know there are several methods for grabbing a

21条回答
  •  隐瞒了意图╮
    2020-11-21 05:39

    Simpler nio usage:

    URL website = new URL("http://www.website.com/information.asp");
    try (InputStream in = website.openStream()) {
        Files.copy(in, target, StandardCopyOption.REPLACE_EXISTING);
    }
    

提交回复
热议问题