title: Java Download mp4 from url
body: <p>I try to download a mp4 file from my Server and save it as a mp4 file. A file is created and has a size of 25 MB, but i can't play it with a video player.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>  HttpURLConnection con = (HttpURLConnection) new URL(serveradress).openConnection();
      con.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; "
              + "Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like 
  Gecko)"
              + " Chrome/53.0.2785.143 Safari/537.36");
      InputStream is = con.getInputStream();
  
  
      System.out.println(con.getResponseCode());
  
      String line = null;
      StringBuilder stringBuilder = new StringBuilder();
  
      BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
  
      while((line = bufferedReader.readLine()) != null) {
          stringBuilder.append(line);
      }
  
      is.close();
  
      String outVideo = stringBuilder.toString(); 
  
  
      File file = new File("C:\\Benutzer\\Admin\\Desktop\\video.mp4");        
      file.getParentFile().mkdirs();
      FileWriter writer = new FileWriter(file);
      writer.write(outVideo);
      writer.close();
  
      } catch(Exception ex) {
          ex.printStacktrace();
      }
  </code></pre>
  
  <p>Any help is really appreciated.</p>