Is this the best way to download a file in java?

后端 未结 4 1828
半阙折子戏
半阙折子戏 2021-01-07 07:20
public void download(String url, String destination) {
        BufferedOutputStream localBufferedOutputStream = null;
        URLConnection localURLConnection = null         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-07 07:38

    You should always look to libraries such as Apache. They have done all the hard work for you: http://commons.apache.org/io/api-release/org/apache/commons/io/FileUtils.html

    I use

    static String   readFileToString(File file)
              Reads the contents of a file into a String using the default encoding for the VM.
    

    quite a lot.

    If you know you have a URL (and so stream) look at: http://commons.apache.org/io/api-1.4/org/apache/commons/io/IOUtils.html

提交回复
热议问题