如果File不是文件或目录,如何找出它? [英] How can I find out if a File is a file or directory if it does not exist?

查看:110
本文介绍了如果File不是文件或目录,如何找出它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

File.isFile() File.isDirectory()不仅在<$ c时返回false $ c>文件不是指定的类型,但是当文件系统上不存在文件本身时。如何确定文件表示文件或目录何时不存在?

File.isFile() and File.isDirectory() both return false not only when the File is not the specified type, but also when the File itself does not exist on the filesystem. How can I determine whether the File represents a file or a directory when it does not exist?

推荐答案

通常,特定路径可以表示目录和文件。在该路径上创建目录或文件之前,它对于其中一个或另一个的概念是无效的。

In general, a specific path can represent both a directory and a file. Until there is either a directory or a file created at that path, the notion of it being for one or the other is invalid.

但是有一个特例。如果路径以路径分隔符结束(在类Unix系统上为'/',在Windows上为'\',在其他系统上可能完全不同),那么至少在类Unix系统上,路径不能是文件的路径。我不知道这对所有系统是否有效。

There is however a special case. If the path ends with a path separator ('/' on Unix-like systems, '\' on Windows and maybe something completely different on other systems), then at least on Unix-like systems the path cannot be that of a file. I do not know if this is valid for all systems though.

这篇关于如果File不是文件或目录,如何找出它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆