Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个非常基本的问题,但不知何故让我感到困惑。通常要检查文件和目录是否存在,我们可以使用布尔值来做到这一点file.exists() 但是我想知道,有没有什么方法可以确定给定路径是目录还是文件。
file.exists()
如果你能提供一些使用 java 的简短示例,那就太好了。
是的,从文档中,有方法isFile和isDirectory
isFile
isDirectory
您可以使用isDirectory和isFile。