什么使文件成为一个文件夹? [英] What makes a file into a folder?
问题描述
文件和文件夹之间的(文件系统特定的)区别是什么?
为什么需要 java.nio.file.Files
中的不同方法来创建这一个或另一个? createDirectory(..)
和 createFile(..)
。两者都使用 Path
作为文件系统对象的句柄/标识符。
一个或另一个失败的情况下(除了使用不同的方法来创建一个或另一个)?
对于创建文件或文件夹,如果已经有一个同名的文件或文件夹,这是一个失败的情况。如果它将是一个r / w文件或文件夹,在文件夹的情况下,可写入的手段文件可能会在其中创建,在文件的情况下,这意味着写入字节 - 是否有区别如何检查?
如果实际上对于失败情况没有区别,我想抽象出一个自定义的 FileSystemObject
他们都是一样的。
好的问题。
最常见的操作系统(Windows,Linux等),一个文件夹可以包含的东西。那些东西有名字每一件东西都可以是一个文件或一个目录。
所以你可能有一些文件夹有以下内容:
a
b
dc
dd
b
是文件。 c
和 d
是文件夹。 a
和 b
只能包含二进制数据。但是 c
和 d
可以包含其他文件/文件夹。
<例如 c
可能如下所示:
afile
anotherfile
d morestuff
d stuff
这样可以使层次结构你想要的深度,结构,但你想要的。这是一个递归数据结构的一个非常基本的例子。选择是否制作文件或文件夹是有用的,因为文件和文件夹是不同类型的东西。一个文件系统可能有文件也是文件夹,但我从来没有见过这样的文件系统。以Windows / Linux为例,如果你制作一个文件,你不能把它作为一个文件夹,你只能改变文件的内容(这只是任意的二进制数据)。
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.
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).
这篇关于什么使文件成为一个文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!