Read Image From Web And Write to File in Java

I’m trying to get a image from a web page and write to a file. But in the end my photo viewer doesn’t recognize the picture file and cant open it(the file is unreadable).

Here is my code:

URL urlpic=new URL("https://static.asset.aparat.com/lp/16107806-6200-m.jpg");//sample pic url
           HttpURLConnection connectionToPicFile=(HttpURLConnection)urlpic.openConnection();
           BufferedReader buffPic=new BufferedReader(new InputStreamReader(connectionToPicFile.getInputStream()));

String pic="";
String alldatapic="";
while((pic=buffPic.readLine())!=null)
               {

                   alldatapic+=pic;
               }

try
               {
FileOutputStream fout=new FileOutputStream("D://pic.jpg");//where i want the file to be saved
               byte[] b=alldatapic.getBytes();
               fout.write(b);
               fout.close();
               }
               catch(Exception ex)
               {
                   System.out.println(ex.toString()+"   "+ex.getMessage());
               }