Java Dropbox Api-下载*.app
我编写了一个名为DropboxHandler的类。这个类管理所有与我的Dropbox帐户直接交互的东西。这个类有一些方法,比如上传和下载文件,列出文件夹中的所有文件,等等。除了使用*.app文件外,一切正常。我知道,这些是文件夹,但我无法找到,如何下载和保存在我的硬盘上。下面是我下载文件夹/文件的方法Java Dropbox Api-下载*.app,java,api,download,dropbox,.app,Java,Api,Download,Dropbox,.app,我编写了一个名为DropboxHandler的类。这个类管理所有与我的Dropbox帐户直接交互的东西。这个类有一些方法,比如上传和下载文件,列出文件夹中的所有文件,等等。除了使用*.app文件外,一切正常。我知道,这些是文件夹,但我无法找到,如何下载和保存在我的硬盘上。下面是我下载文件夹/文件的方法 public static void downloadFolder(String fileToDownload, String tempFileName) throws IOException {
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());
}
}
我想你没有说问题出在哪里。您已粘贴了一些代码,但尚未解释出现了什么问题。你有错误吗?堆栈跟踪是什么?或者该应用程序是否做了一些与您期望不同的事情?如果是的话,你期望什么?观察到的行为是什么?对不起,我忘了提到^^^啊啊,我看到我的问题了。递归调用该方法时,输出流仍处于打开状态。你的版本可以运行,但现在下载完所有内容后,我尝试运行该应用程序,但它说,该应用程序无法启动。现在怎么了?我所能做的就是猜测,因为我没有访问文件夹的权限,但可能有文件权限?也许正确的文件没有标记为可执行文件?