开发者

Why is File.isAbsolute() platform dependent when the File class is platform independent?

From th开发者_开发百科e File class JavaDoc:

An abstract representation of file and directory pathnames.

User interfaces and operating systems use system-dependent pathname strings to name files and directories. This class presents an abstract, system-independent view of hierarchical pathnames.

Why is the method .isAbsolute() platform dependant? (return different result for /tmp on Win and Linux) and doesn't check if the file is absolute either or Linux or Windows? How can the File class guess which platform's file I am trying to represent via the File in my code? I am not necessarily representing local file system's file.


It has to have some idea of which platform you're interested in, and the current platform is a pretty good guess!

On Linux /tmp is absolute. On Windows it isn't - it's relative to your current drive.


I am not necessarily representing local file system's file

Then you should not use File, File provides easy access to the local filesystem and is not meant to represent non-local resources.

There are other System independent classes like URI and URL you should use instead(URL has some design flaws so prefer URI).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜