Box API Java: 如何将文件移动到另一个文件夹?

Box API Java: How can I move a file into another folder?

所以我想将一个文件移动到另一个文件夹中。 方框 api 表示以下

To move a folder, update the ID of its parent.

但是BoxItem.Info上好像没有setID()方法,好像有setName()

我正在尝试做类似于 api 示例的事情 here

BoxFile file = new BoxFile(api, fileID);
BoxFile.Info info = file.new Info();
String parentID = info.getParent().getID();

BoxFolder parentFolder = new BoxFolder(api, parentID);
BoxFolder.Info parentInfo = parentFolder.new Info();

parentInfo.setID(newID); // Method doesn't exist

parentFolder.updateInfo(parentInfo);

对我来说似乎也很奇怪,没有一个文件方法可以简单地.move(),它存在于文件夹中。

不使用 updateInfo 方法,而是对要与目标文件夹一起移动的文件使用 move(BoxFolder destination)

代码示例:

String fileID = "1234";
String destinationFolderID = "5678";
BoxFile file = new BoxFile(api, fileID);
BoxFolder destinationFolder = new BoxFolder(destinationFolderID);
file.move(destinationFolder)

此外,为避免目标文件夹中的名称冲突,您可以选择为文件提供一个新名称 move(BoxFolder destination, String newName)。文件将以新名称放入目标文件夹。

代码示例:

String fileID = "1234";
String destinationFolderID = "5678";
BoxFile file = new BoxFile(api, fileID);
BoxFolder destinationFolder = new BoxFolder(destinationFolderID);
file.move(destinationFolder, "Vacation Photo (1).jpg");