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

前端 未结 21 2977
情深已故
情深已故 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条回答
  •  旧时难觅i
    2020-11-21 05:47

    1st Method using the new channel

    ReadableByteChannel aq = Channels.newChannel(new url("https//asd/abc.txt").openStream());
    FileOutputStream fileOS = new FileOutputStream("C:Users/local/abc.txt")
    FileChannel writech = fileOS.getChannel();
    

    2nd Method using FileUtils

    FileUtils.copyURLToFile(new url("https//asd/abc.txt",new local file on system("C":/Users/system/abc.txt"));
    

    3rd Method using

    InputStream xy = new ("https//asd/abc.txt").openStream();
    

    This is how we can download file by using basic java code and other third-party libraries. These are just for quick reference. Please google with the above keywords to get detailed information and other options.

提交回复
热议问题