[英]Java Dropbox Api - Download *.app
I've coded a Class called DropboxHandler. 我已经编写了一个名为DropboxHandler的类。 This class manages all the stuff that interacts directly with my Dropbox account.
此类管理与我的Dropbox帐户直接互动的所有内容。 This class has some methods like uploading and downloading a file, listing all files in a folder, and so on.
此类具有一些方法,例如上载和下载文件,列出文件夹中的所有文件等等。 Everything works fine, except with *.app Files.
一切正常,除了* .app文件。 I know, that these are folders, but i cannot find out, how to download and save them on my HD.
我知道,这些是文件夹,但是我找不到如何下载并将其保存在HD上的信息。 Here is my method to download an Folder/ File
这是我下载文件夹/文件的方法
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");
}
}
When i run my code, it creates a Folder called Launcher.app (Launcher is the File to download). 当我运行代码时,它将创建一个名为Launcher.app的文件夹(Launcher是要下载的文件)。 But when it should download the content of the Launcher, the FileOutputStream fires an error that says that Launcher.app/Content isn't a Folder.
但是,当它应下载Launcher的内容时,FileOutputStream会引发错误,指出Launcher.app/Content不是文件夹。
So maybe anyone has some Ideas, how to download the *.app "Files" 因此,也许任何人都有一些想法,如何下载* .app“文件”
Greetings 问候
There are a number of issues with the code you posted. 您发布的代码存在许多问题。 The one you're hitting now is that the very first line of the method creates a file with the same name as the folder you want to write to.
您现在要单击的是该方法的第一行创建的文件名称与您要写入的文件夹相同。
I think that the next issue you'll hit is where you call getFile
. 我认为您遇到的下一个问题是调用
getFile
。 It looks like you're trying to save every file into the same output stream. 您似乎正在尝试将每个文件保存到同一输出流中。 So essentially you're creating a file (instead of a folder) called
Launcher.app
and then writing the contents of every file into that file (maybe concatenated together as one big file). 因此,实质上,您是在创建一个名为
Launcher.app
的文件(而不是文件夹),然后将每个文件的内容写入该文件(可能被串联在一起成为一个大文件)。
I took a stab at fixing the code, but I haven't tested it at all. 我在修改代码时遇到了麻烦,但是我还没有对其进行测试。 (I don't even know if it compiles.) See if this helps:
(我什至不知道它是否可以编译。)看看是否有帮助:
// 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.