Downloading files with Java

前端 未结 2 1776
青春惊慌失措
青春惊慌失措 2021-02-04 01:11

I\'ve written a bit of code for downloading an episode of a webcast I do. It gets the URL of the episode and gets the place to save it. However, it only downloads up to 16MB and

2条回答
  •  情话喂你
    2021-02-04 01:29

    here's another solution :

    import java.io.*;
    import java.net.*;
    public class DownloadFile
    {
    
        public static void main(String args[]) throws IOException
        {
    
            java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL(episode.getUrl()).openStream());
            java.io.FileOutputStream fos = new java.io.FileOutputStream(episode.getLocalSave());
            java.io.BufferedOutputStream bout = new BufferedOutputStream(fos);
            byte data[] = new byte[1024];
            int read;
            while((read = in.read(data,0,1024))>=0)
            {
                bout.write(data, 0, read);
            }
            bout.close();
            in.close();
        }
    }
    

提交回复
热议问题