I'm writing a swing application, but I'm sure I'll think of more to add to it later, so I would like a way to download the file from dropbox if its new. I've tried a lot of different things, but all they give me are the page's HTML. Anyone know how to do this? I sure don't.
-
So, what have you tried - can you post some code so we can help you make it work. – wattostudios Nov 26 '12 at 01:48
-
5I understand dropbox provides APIs for this. See https://www.dropbox.com/developers/reference/sdk – hoipolloi Nov 26 '12 at 01:49
-
If you are using the client software that maps a local folder to your dropbox account, then the folder will always contain the latest version of each file - is that what you are after? – Romski Nov 26 '12 at 01:50
-
2Take a look at the [Dropbox API](https://www.dropbox.com/developers) – MadProgrammer Nov 26 '12 at 01:50
-
@hoipolloi I had no idea there were such things! Thanks! – TheNerdyCoder Nov 26 '12 at 01:51
1 Answers
In my opinion, the Dropbox API is far too complicated for what you need. It's actually extremely simple to download a file from dropbox.
The first step is to put the file that you want to download somewhere inside your dropbox's Public Folder.
Next you want to right click that file and choose "copy public link." You can do this from the web interface or even right there in your computer-sync-folder-thing. This will give you a unique download url for 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 value of the url string to your own download url, and the value of filename to whatever you want to save the file as.
Now, if this fails, you may need to change the url from https:// to http://, but either way it should still work. Dropbox is cool like that.

- 51
- 6
-
1However, if you have something against putting your file in the public folder, then you will actually have to use the Dropbox API that the other comments are talking about. – Daniel K Dec 16 '13 at 21:24
-
I'm trying to download a JAR file but it's resulting in a corrupt jar file error. This was working like a charm earlier but not anymore. Strange. – Shivaji_Vidhale Jul 30 '15 at 23:07
-
1You don't need to call flush() if you are immediately calling close(). – ceklock Nov 09 '15 at 00:29