查找对象类型及其路径

问题描述 投票:1回答:1

我必须找出具有目录路径的对象的类型(文件夹/文件)。

例如我必须找出具有此路径的对象是一个文件。

/home/user/test.docx

我找到了一个可行的解决方案,但实际上并不是一个很好的解决方案。

try {
    final Folder parentFolder = (Folder) session.getObjectByPath(path); 
    //throws exception when path points to a file
    //do sth when it's a folder
} catch (final Exception e) {
    //do sth when it's a document/file
}

我不能在这里使用'instance of',因为我无法在不知道输出类型的情况下获取对象(使用session.getObjectByPath)。

是否有更好的方法来找出带有其路径的对象类型?

java cmis
1个回答
0
投票

而不是直接将其强制转换为Folder,您可以像这样检查instanceof:

© www.soinside.com 2019 - 2024. All rights reserved.