什么是 Java 中的“常规文件”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20547268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is a "regular file" in Java?
提问by Thunderforge
The class BasicFileAttributes, for examining the properties of a file in the file system, has the method isRegularFile(). Unfortunately, the Javadoc description is rather lacking:
用于检查文件系统中文件属性的BasicFileAttributes类具有方法isRegularFile()。不幸的是,Javadoc 描述相当缺乏:
Tells whether the file is a regular file with opaque content.
告诉文件是否是具有不透明内容的常规文件。
What does this mean? What exactly is a regular file with opaque content? I can tell from the other methods in the class that it's not a directory or symbolic link, so I'm inclined to think that it's everything else. However, there apparently is some type of "irregular file" because a method exists called isOther(), which returns true if it's not a directory, symbolic link, or "regular file".
这是什么意思?具有不透明内容的常规文件究竟是什么?我可以从类中的其他方法看出它不是目录或符号链接,所以我倾向于认为它是其他一切。但是,显然存在某种类型的“不规则文件”,因为存在一个名为isOther()的方法,如果它不是目录、符号链接或“常规文件”,则返回 true。
So what exactly is an regular file in Java?
那么Java中的常规文件究竟是什么?
采纳答案by Jorgesys
For example in UNIX, a regular file is one that is not special in some way. Special files include symbolic links and directories. A regular file is a sequence of bytes stored permanently in a file system.
例如,在 UNIX 中,常规文件在某些方面并不特殊。特殊文件包括符号链接和目录。常规文件是永久存储在文件系统中的字节序列。
Read this answer @ UNIX & Linux stackexchange: What is a regular file?
阅读此答案@UNIX & Linux stackexchange:什么是常规文件?
I figure rm -i is an alias, possibly rm -i. The "regular" part doesn't mean anything in particular, it only means that it's not a pipe, device, socket or anything other "special".
it means the file is not a symlink, pipe, rand, null, cpu, etc. Perhaps you have heard the linux philosophy everything is a text. This isn't literally true, but it suggests a dominant operational context where string processing tools can be applied to filesystem elements directly. In this case, it means that in a more literal fashion. To see the detection step in isolation, try the command file, as in file /etc/passwd or file /dev/null.
我认为 rm -i 是一个别名,可能是 rm -i。“常规”部分没有特别的含义,它仅表示它不是管道、设备、套接字或任何其他“特殊”的东西。
这意味着文件不是符号链接、管道、rand、null、cpu 等。也许您已经听说过 linux 哲学,一切都是文本。这不是字面上的真实,但它表明了一个占主导地位的操作上下文,其中字符串处理工具可以直接应用于文件系统元素。在这种情况下,这意味着以更字面的方式。要单独查看检测步骤,请尝试命令文件,如文件 /etc/passwd 或文件 /dev/null。
回答by Jorge Campos
From Files Reference - AIX IBM
A file is a collection of data that can be read from or written to. A file can be a program you create, text you write, data you acquire, or a device you use. Commands, printers, terminals, and application programs are all stored in files. This allows users to access diverse elements of the system in a uniform way and gives the operating system great flexibility. No format is implied when a file is created.
文件是可以读取或写入的数据的集合。文件可以是您创建的程序、您编写的文本、您获取的数据或您使用的设备。命令、打印机、终端和应用程序都存储在文件中。这允许用户以统一的方式访问系统的不同元素,并为操作系统提供了极大的灵活性。创建文件时不暗示任何格式。
There are three types of files
共有三种类型的文件
- Regular - Stores data (text, binary, and executable).
- Directory - Contains information used to access other files.
- Special - Defines a FIFO (first-in, first-out) file or a physical device.
- 常规 - 存储数据(文本、二进制和可执行文件)。
- 目录 - 包含用于访问其他文件的信息。
- 特殊 - 定义 FIFO(先进先出)文件或物理设备。
Regular filesare the most common. When a word processing program is used to create a document, both the program and the document are contained in regular files.
常规文件是最常见的。当使用文字处理程序创建文档时,程序和文档都包含在常规文件中。
Regular filescontain either text or binary information. Text files are readable by the user. Binary files are readable by the computer. Binary files can be executable files that instruct the system to accomplish a job. Commands, shell scripts, and other programs are stored in executable files.
常规文件包含文本或二进制信息。用户可以读取文本文件。二进制文件可由计算机读取。二进制文件可以是指示系统完成工作的可执行文件。命令、shell 脚本和其他程序存储在可执行文件中。
Directoriescontain information the system needs to access all types of files, but they do not contain the actual file data. As a result, directories occupy less space than a regular file and give the file-system structure flexibility and depth. Each directory entry represents either a file or subdirectory and contains the name of a file and the file's i-node (index node reference) number. The i-node number represents the unique i-node that describes the location of the data associated with the file. Directories are created and controlled by a separate set of commands. See "Directories" in Operating system and device management for more information.
目录包含系统访问所有类型文件所需的信息,但不包含实际的文件数据。因此,目录占用的空间比普通文件少,并赋予文件系统结构灵活性和深度。每个目录条目代表一个文件或子目录,并包含文件名和文件的索引节点(索引节点引用)编号。i-node 编号表示唯一的 i-node,它描述了与文件关联的数据的位置。目录由一组单独的命令创建和控制。有关详细信息,请参阅操作系统和设备管理中的“目录”。
Special filesdefine devices for the system or temporary files created by processes. There are three basic types of special files: FIFO (first-in, first-out), block, and character. FIFO files are also called pipes. Pipes are created by one process to temporarily allow communication with another process. These files cease to exist when the first process finishes. Block and character files define devices.
特殊文件定义系统设备或进程创建的临时文件。特殊文件有三种基本类型:FIFO(先进先出)、块和字符。FIFO 文件也称为管道。管道由一个进程创建以临时允许与另一个进程通信。当第一个进程完成时,这些文件将不复存在。块和字符文件定义设备。
All this above is from the first link. I've checked in many other sources regarding Operational Systems differences and it seems this one is the most common definition on all sources i've found.
以上所有内容均来自第一个链接。我已经检查了许多关于操作系统差异的其他来源,似乎这是我发现的所有来源中最常见的定义。
回答by FrVaBe
I am not an expert on this but at the first look BasicFileAttributes
is not a class but an interface. So whatever a regular file is depends on the implementation of this interface. I can see that there is e.g. the class WindowsFileAttributs
that implements this interface.
我不是这方面的专家,但乍一看BasicFileAttributes
不是类而是接口。因此,无论常规文件是什么,都取决于此接口的实现。我可以看到有WindowsFileAttributs
实现这个接口的类。
If you have a look at the OpenJDK versionof this class you will find that it is
如果您查看该类的OpenJDK 版本,您会发现它是
!isSymbolicLink() && !isDirectory() && !isOther();
Get all other information from the code ;-)
从代码中获取所有其他信息;-)