48

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:

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".

So what exactly is an regular file in Java?

Thunderforge
  • 19,637
  • 18
  • 83
  • 130
  • 1
    Found [this question](http://stackoverflow.com/questions/16505508/what-opaque-content-exactly-mean) that focuses more on the opaque content portion. Doesn't seem to answer your whole question though. – thegrinner Dec 12 '13 at 15:20
  • 2
    On *nix systems there are also device nodes, fifos, and local sockets in the file system. Maybe that's the sort of "other" it means? – FatalError Dec 12 '13 at 15:21
  • @FatalError, so is the term only relevant on *nix systems, but not on systems like Windows? – Thunderforge Dec 12 '13 at 15:23
  • @Thunderforge Well, I'm not aware of any on Windows but I'm not a Windows developer, so I can't say for certain. – FatalError Dec 12 '13 at 15:25
  • Title should be 'What is a "regular file" in Java?' ;-) – FrVaBe Dec 12 '13 at 15:41
  • @Thunderforge I didn't know either. +1 for interesting question. – FrVaBe Dec 12 '13 at 15:50

3 Answers3

26

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.

Read this answer @ UNIX & Linux stackexchange: What is a regular file?

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.

Community
  • 1
  • 1
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
  • 2
    Does this term also apply to Windows and other platforms? – Thunderforge Dec 12 '13 at 15:45
  • 1
    As to relevance in Windows, I believe the NTFS file system actual supports its own form of symbolic links, you only need a specific tool to be able to create them. – Gimby Dec 12 '13 at 16:48
  • Some file systems are not "permanent"; e.g. a tmpfs file system. In fact, the only entirely accurate distinction is that a regular file is NOT a directory or some kind of "special" file. Java is only trying to describe features of the host operating system. – Stephen C Jul 05 '18 at 14:14
11

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.

Regular files are 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 files contain 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.

Directories contain 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.

Special files define 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.

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.

Jorge Campos
  • 22,647
  • 7
  • 56
  • 87
8

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.

If you have a look at the OpenJDK version of this class you will find that it is

!isSymbolicLink() && !isDirectory() && !isOther();

Get all other information from the code ;-)

FrVaBe
  • 47,963
  • 16
  • 124
  • 157