Java Files  «Prev  Next»


Lesson 2File, directories, and paths review
ObjectiveTest your knowledge of files, file attributes, filenames, directories, and paths.

Review of Java File Directories Paths

File I/O

File I/O occurs within the context of a filesystem. A filesystem is a very different thing from a disk. Disks store data in sectors, which are usually 512 bytes each and are hardware devices that know nothing about the semantics of files. Disks simply provide a number of slots where data can be stored. In this respect, the sectors of a disk are similar to memory pages; all are of uniform size and are addressable as a large array.
A filesystem is a higher level of abstraction. Filesystems are a particular method of arranging and interpreting data stored on a disk (or some other random-access, block-oriented device). The code you write almost always interacts with a filesystem, not with the disks directly. It is the filesystem that defines the abstractions of filenames, paths, files, file attributes, etc.
All I/O is done by means of demand paging. You will recall that paging is very low level and always happens as direct transfers of disk sectors into and out of memory pages.
Question: How does this low-level paging translate to file I/O, which can be performed in arbitrary sizes and alignments?
A filesystem organizes a sequence of uniformly sized data blocks. Some blocks store meta information such as maps of free blocks, directories, and indexes. Other blocks contain file data. The meta information about individual files describes which blocks contain the file data, where the data ends, and when it was last updated.
When a request is made by a user process to read file data, the filesystem implementation determines exactly where on disk that data lives. It then takes action to bring those disk sectors into memory. In older operating systems, this usually meant issuing a command directly to the disk driver to read the needed disk sectors. But in modern, paged operating systems, the filesystem takes advantage of demand paging to bring data into memory.
Filesystems also have a notion of pages, which may be the same size as a basic memory page or a multiple of it. Typical filesystem page sizes range from 2,048 to 8,192 bytes and will always be a multiple of the basic memory page size.

Skills Check

If you are comfortable with the material covered in this quiz, then you are ready to move on in the course.
If you are not comfortable with the material covered in the quiz, click on the Search button located above to search on those topics not understood. You will find links to material on file basics, cross-platform filenames, directories and paths, relative and absolute paths, and file attributes.

Files Directories Paths - Quiz

Click the Quiz Link below to take a multiple-choice quiz on files, filenames, file attributes, directories, and paths.
Files Directories Paths - Quiz