panny
panny

Reputation: 2212

create file, exception cases in java

In Java (newer version) and windows xp (ntfs):

1 - Existing file f, Files.createFile(Paths.get(f)) : FileAlreadyExistsException

2 - Existing file f, Files.createDirectory(Paths.get(f)) : FileAlreadyExistsException

3 - Existing folder fo, Files.createDirectory(Paths.get(fo)) : FileAlreadyExistsException

4 - Existing folder fo, Files.createFile(Paths.get(fo)) : AccessDeniedException

Why is the last one different?

Linked to this question, what is the conceptual difference ?

Doesn't it mean for a folder or a file the same when they are "writable". Or a locked file or folder, you can't access the content.

I think actually of a folder as a file with a contents list. You can open it actually with vim. So in the end, why are all filesystem elements which contain binary or textual data. This two fold policy is making stuff complicated. In this respect I actually do like the unix philosophy of files. It doesn't make a difference between folders, files and device files (special files).

And as hierarchical filesystem structure is actually the gof4 composite pattern I think I'm right, it is abstracting away a "Filesystemelement" as well.

Why is Java complicating things here?

Upvotes: 0

Views: 599

Answers (1)

Hunter Zhao
Hunter Zhao

Reputation: 4649

aha, the reason is just there existing a folder(not a file), so the exception type mustn't be FileAlreadyExistsException.

Upvotes: 1

Related Questions