2013-12-16 81 views
1

我的代码如下:获得文件大小

requestObj.addField(BoxFolder.FIELD_SIZE); 
    BoxCollection itemCollection = client.getFoldersManager().getFolderItems(file.getId(), 
      (BoxFolderRequestObject) requestObj); 
    List<BoxTypedObject> objects = itemCollection.getEntries(); 
    for (BoxTypedObject innerFile : objects) { 
     System.out.println("=============" + innerFile.getExtraData(BoxFolder.FIELD_SIZE)); 
     System.out.println("=============" + innerFile.getValue(BoxFolder.FIELD_SIZE)); 

    } 

这两个System.out的

我看着BoxTypedObject它没有办法返回返回null文件大小。

我看到的getSize()在BoxItem,但不是由Box.getFolderItems ---> BoxCollection ----> BoxTypedObject

返回请提供一种方式来获得文件盒大小

更多的上下文:

https://github.com/box/box-java-sdk-v2/issues/58

回答

1

BoxTypedObject可以是各种类型。 您可以这样做: if(innerFile instanceof BoxItem){ size =((BoxItem)innerFile).getSize(); }