从java中的dropbox下载文件 [英] Downloading file from dropbox in java

查看:120
本文介绍了从java中的dropbox下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个秋千应用程序,但我相信我会想到更多的添加到它以后,所以我想要一种方法从Dropbox下载文件,如果它的新的。我尝试了很多不同的东西,但他们给我的都是页面的HTML。任何人都知道如何做到这一点我确实不会。

解决方案

在我看来,Dropbox API对于你需要的太复杂了。
从dropbox下载文件实际上非常简单。



第一步是将要下载的文件放在您的保管箱的公用文件夹中。



接下来,您要右键单击该文件,然后选择复制公共链接。你可以从网页界面,甚至在你的电脑同步文件夹的东西。这将为您提供一个唯一的下载网址。



接下来,使用以下代码:

  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(); }

当然,将url字符串的值更改为您自己的下载URL,文件名到您要保存文件的任何文件。



现在,如果失败,您可能需要将URL从https://更改为http://,但任何一种方式它仍然可以工作。 Dropbox很酷。


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.

解决方案

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.

这篇关于从java中的dropbox下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆