[英]Java Dropbox Api - Download *.app
我已经编写了一个名为DropboxHandler的类。 此类管理与我的Dropbox帐户直接互动的所有内容。 此类具有一些方法,例如上载和下载文件,列出文件夹中的所有文件等等。 一切正常,除了* .app文件。 我知道,这些是文件夹,但是我找不到如何下载并将其保存在HD上的信息。 这是我下载文件夹/文件的方法
public static void downloadFolder(String fileToDownload, String tempFileName) throws IOException {
FileOutputStream outputStream = new FileOutputStream(tempFileName);
try {
DbxEntry.WithChildren listing = client.getMetadataWithChildren(fileToDownload);
for (DbxEntry child : listing.children) {
if (child instanceof DbxEntry.Folder) {
(new File(tempFileName)).mkdirs();
downloadFolder(fileToDownload + "/" + child.name, tempFileName + "/" + child.name);
} else if (child instanceof DbxEntry.File) {
DbxEntry.File downloadedFile = client.getFile(fileToDownload, null, outputStream);
System.out.println("Metadata: " + downloadedFile.toString());
System.out.println("Downloaded: " + downloadedFile.toString());
}
}
} catch (DbxException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
} finally {
outputStream.close();
System.out.println("Download finished");
}
}
当我运行代码时,它将创建一个名为Launcher.app的文件夹(Launcher是要下载的文件)。 但是,当它应下载Launcher的内容时,FileOutputStream会引发错误,指出Launcher.app/Content不是文件夹。
因此,也许任何人都有一些想法,如何下载* .app“文件”
问候
您发布的代码存在许多问题。 您现在要单击的是该方法的第一行创建的文件名称与您要写入的文件夹相同。
我认为您遇到的下一个问题是调用getFile
。 您似乎正在尝试将每个文件保存到同一输出流中。 因此,实质上,您是在创建一个名为Launcher.app
的文件(而不是文件夹),然后将每个文件的内容写入该文件(可能被串联在一起成为一个大文件)。
我在修改代码时遇到了麻烦,但是我还没有对其进行测试。 (我什至不知道它是否可以编译。)看看是否有帮助:
// recursively download a folder from Dropbox to the local file system
public static void downloadFolder(String path, String destination) throws IOException {
new File(destination).mkdirs();
try {
for (DbxEntry child : client.getMetadataWithChildren(path).children) {
if (child instanceof DbxEntry.Folder) {
// recurse
downloadFolder(path + "/" + child.name, destination + "/" + child.name);
} else if (child instanceof DbxEntry.File) {
// download an individual file
OutputStream outputStream = new FileOutputStream(
destination + "/" + child.name);
try {
DbxEntry.File downloadedFile = client.getFile(
path + "/" + child.name, null, outputStream);
} finally {
outputStream.close();
}
}
}
} catch (DbxException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.