<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Why this code do not download files in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Why-this-code-do-not-download-files/m-p/188171#M7999</link>
    <description>&lt;PRE class="text"&gt;public class HttpDownloader {
&amp;nbsp;
    public static void main(String[] args) {
        String fileURL = "https://www.dropbox.com/s/vc0dbvag0lff47a/Paczka.zip?dl=1";
        String saveDir = "E:/Download";
        try {
            HttpDownloadUtility.downloadFile(fileURL, saveDir);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;PRE class="text"&gt;public class HttpDownloadUtility {
    private static final int BUFFER_SIZE = 4096;
&amp;nbsp;
    public static void downloadFile(String fileURL, String saveDir)
            throws IOException {
        URL url = new URL(fileURL);
        HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
        int responseCode = httpConn.getResponseCode();
&amp;nbsp;
        if (responseCode == HttpURLConnection.HTTP_OK) {
            String fileName = "";
            String disposition = httpConn.getHeaderField("Content-Disposition");
            String contentType = httpConn.getContentType();
            int contentLength = httpConn.getContentLength();
&amp;nbsp;
            if (disposition != null) {
                int index = disposition.indexOf("filename=");
                if (index &amp;gt; 0) {
                    fileName = disposition.substring(index + 10,
                            disposition.length() - 1);
                }
            } else {
                fileName = fileURL.substring(fileURL.lastIndexOf("/") + 1,
                        fileURL.length());
            }
&amp;nbsp;
            System.out.println("Content-Type = " + contentType);
            System.out.println("Content-Disposition = " + disposition);
            System.out.println("Content-Length = " + contentLength);
            System.out.println("fileName = " + fileName);
&amp;nbsp;
            InputStream inputStream = httpConn.getInputStream();
            String saveFilePath = saveDir + File.separator + fileName;
&amp;nbsp;
            FileOutputStream outputStream = new FileOutputStream(saveFilePath);
&amp;nbsp;
            int bytesRead = -1;
            byte[] buffer = new byte[BUFFER_SIZE];
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }
&amp;nbsp;
            outputStream.close();
            inputStream.close();
&amp;nbsp;
            System.out.println("File downloaded");
        } else {
            System.out.println("No file to download. Server replied HTTP code: " + responseCode);
        }
        httpConn.disconnect();
    }
}&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;hey my question is why this Java code do not work with my direct dropbox link?&lt;BR /&gt;&lt;BR /&gt;And how can i fix it or what should i do ? Because i dont have any idea why it do not work fine &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@EA4D5AD6084EAC95CB4E739348E74CC6/emoticons/1f615.png" alt=":confused_face:" title=":confused_face:" /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 29 May 2019 09:30:20 GMT</pubDate>
    <dc:creator>BaX M.</dc:creator>
    <dc:date>2019-05-29T09:30:20Z</dc:date>
    <item>
      <title>Why this code do not download files</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Why-this-code-do-not-download-files/m-p/188171#M7999</link>
      <description>&lt;PRE class="text"&gt;public class HttpDownloader {
&amp;nbsp;
    public static void main(String[] args) {
        String fileURL = "https://www.dropbox.com/s/vc0dbvag0lff47a/Paczka.zip?dl=1";
        String saveDir = "E:/Download";
        try {
            HttpDownloadUtility.downloadFile(fileURL, saveDir);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;PRE class="text"&gt;public class HttpDownloadUtility {
    private static final int BUFFER_SIZE = 4096;
&amp;nbsp;
    public static void downloadFile(String fileURL, String saveDir)
            throws IOException {
        URL url = new URL(fileURL);
        HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
        int responseCode = httpConn.getResponseCode();
&amp;nbsp;
        if (responseCode == HttpURLConnection.HTTP_OK) {
            String fileName = "";
            String disposition = httpConn.getHeaderField("Content-Disposition");
            String contentType = httpConn.getContentType();
            int contentLength = httpConn.getContentLength();
&amp;nbsp;
            if (disposition != null) {
                int index = disposition.indexOf("filename=");
                if (index &amp;gt; 0) {
                    fileName = disposition.substring(index + 10,
                            disposition.length() - 1);
                }
            } else {
                fileName = fileURL.substring(fileURL.lastIndexOf("/") + 1,
                        fileURL.length());
            }
&amp;nbsp;
            System.out.println("Content-Type = " + contentType);
            System.out.println("Content-Disposition = " + disposition);
            System.out.println("Content-Length = " + contentLength);
            System.out.println("fileName = " + fileName);
&amp;nbsp;
            InputStream inputStream = httpConn.getInputStream();
            String saveFilePath = saveDir + File.separator + fileName;
&amp;nbsp;
            FileOutputStream outputStream = new FileOutputStream(saveFilePath);
&amp;nbsp;
            int bytesRead = -1;
            byte[] buffer = new byte[BUFFER_SIZE];
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }
&amp;nbsp;
            outputStream.close();
            inputStream.close();
&amp;nbsp;
            System.out.println("File downloaded");
        } else {
            System.out.println("No file to download. Server replied HTTP code: " + responseCode);
        }
        httpConn.disconnect();
    }
}&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;hey my question is why this Java code do not work with my direct dropbox link?&lt;BR /&gt;&lt;BR /&gt;And how can i fix it or what should i do ? Because i dont have any idea why it do not work fine &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@EA4D5AD6084EAC95CB4E739348E74CC6/emoticons/1f615.png" alt=":confused_face:" title=":confused_face:" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 09:30:20 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Why-this-code-do-not-download-files/m-p/188171#M7999</guid>
      <dc:creator>BaX M.</dc:creator>
      <dc:date>2019-05-29T09:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: Why this code do not download files</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Why-this-code-do-not-download-files/m-p/188172#M8000</link>
      <description>&lt;P&gt;What happens when you run this code? Do you get an exception?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2016 01:19:25 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Why-this-code-do-not-download-files/m-p/188172#M8000</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2016-09-06T01:19:25Z</dc:date>
    </item>
  </channel>
</rss>

