Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
public class HttpDownloader { 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(); } } }
public class HttpDownloadUtility { private static final int BUFFER_SIZE = 4096; public static void downloadFile(String fileURL, String saveDir) throws IOException { URL url = new URL(fileURL); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); int responseCode = httpConn.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { String fileName = ""; String disposition = httpConn.getHeaderField("Content-Disposition"); String contentType = httpConn.getContentType(); int contentLength = httpConn.getContentLength(); if (disposition != null) { int index = disposition.indexOf("filename="); if (index > 0) { fileName = disposition.substring(index + 10, disposition.length() - 1); } } else { fileName = fileURL.substring(fileURL.lastIndexOf("/") + 1, fileURL.length()); } System.out.println("Content-Type = " + contentType); System.out.println("Content-Disposition = " + disposition); System.out.println("Content-Length = " + contentLength); System.out.println("fileName = " + fileName); InputStream inputStream = httpConn.getInputStream(); String saveFilePath = saveDir + File.separator + fileName; FileOutputStream outputStream = new FileOutputStream(saveFilePath); int bytesRead = -1; byte[] buffer = new byte[BUFFER_SIZE]; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } outputStream.close(); inputStream.close(); System.out.println("File downloaded"); } else { System.out.println("No file to download. Server replied HTTP code: " + responseCode); } httpConn.disconnect(); } }
hey my question is why this Java code do not work with my direct dropbox link?
And how can i fix it or what should i do ? Because i dont have any idea why it do not work fine 😕
What happens when you run this code? Do you get an exception?
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!