Downloading file from dropbox in java

后端 未结 1 467
悲哀的现实
悲哀的现实 2021-01-19 00:36

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

相关标签:
1条回答
  • 2021-01-19 01:23

    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.

    0 讨论(0)
提交回复
热议问题