What makes a file into a folder? [closed]

瘦欲@ 提交于 2019-12-13 06:24:37

问题


What is the (file system specific) difference between a file and a folder?

Why are different methods in java.nio.file.Files required to create the one or the other? createDirectory(..) and createFile(..). Both use Path as a handle / identifier for the file system object.

Should I think of something special while creating one or the other as of failure cases (besides using different methods for creating the one or the other) ?

For the creation of a file or folder, if there is already a file or folder with the same name, this is a failure case. If it is going to be an r/w file or folder, in the folder case writable means files may be created in it and in the file case it means writing bytes to it - is there a difference how to check this ?

If actually there is no difference for the failure cases, I would like to abstract away a custom FileSystemObject and treat them all the same.


回答1:


Good question.

In the most common operating systems (Windows, Linux, etc.), a folder can contain things. Those things have names. Each thing can either be a file or a directory.

So you might have some folder that has the following:

  a
  b
d c
d d

a and b are files. c and d are folders. a and b can only contain binary data. But c and d can contain other files/folders.

For example c might look like this:

  afile
  anotherfile
d morestuff
d stuff

This allows you to make a hierarchy as deep as you want, structured however you want. It is a very basic example of a recursive data structure. It's useful to choose whether you're making a file or folder since files and folders are separate types of things. A filesystem could have files that are also folders, but I've never seen any filesystem like that. In Windows/Linux for example if you make a file, you can't use it as a folder, you can only change the contents of the file (which is just arbitrary binary data).



来源:https://stackoverflow.com/questions/15540191/what-makes-a-file-into-a-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!