Download file from Dropbox in java

I am writing a swing application, but I am sure that I will think about adding it later, so I would like to download the file from Dropbox if it is new. I tried many different things, but all they give me is HTML pages. Does anyone know how to do this? I'm sure not.

+4
source share
1 answer

In my opinion, the Dropbox API is too complex for what you need. It’s actually very easy to download a file from Dropbox.

The first step is to put the file you want to upload somewhere inside your Dropbox public folder.

Next, you want to right-click this file and select "copy public link". You can do this from the web interface or even right there in your sync folder. This will give you a unique URL to download the file.

Next, use this code:

String url="https://dl.dropboxusercontent.com/u/73386806/Prune%20Juice/Prune%20Juice.exe"; String filename="PruneJuice.exe"; try{ URL download=new URL(url); ReadableByteChannel rbc=Channels.newChannel(download.openStream()); FileOutputStream fileOut = new FileOutputStream(filename); fileOut.getChannel().transferFrom(rbc, 0, 1 << 24); fileOut.flush(); fileOut.close(); rbc.close(); }catch(Exception e){ e.printStackTrace(); } 

Of course, change the url string value to your own download url and the file name value so that you want to save the file.

Now, if that fails, you may need to change the URL from https: // to http: //, but it will work anyway. Dropbox is awesome.

+4
source

All Articles