Java Reference
In-Depth Information
C H A P T E R 8
Interacting with Filesystems
Applications often interact with the filesystem to output data to and/or input data from
files.Java'sstandardclasslibrarysupportsfilesystemaccessviaitsclassic
File
,
Ran-
RandomAccessFile
, and various stream and writer/reader APIs.
Note
Althoughit'spreferredtoaccessfilesystemsviaJava'sNewI/OAPIs,Idon't
discussNewI/OinthischapterbecauseaspectsofNewI/Oinvolvenetworking,which
I don't discuss until
Chapter 9
. Also, you should know about this chapter's classic I/O
APIsbecauseyou'llencounterthemwhilemodifyinglegacycodethatusesclassicI/O.
I discuss New I/O in Appendix C.
File
Applicationsofteninteractwitha
filesystem
,whichisusuallyexpressedasahierarchyof
files and directories starting from a
root directory
.
WindowsandotherplatformsonwhichaJavaVirtualMachine(JVM)runstypically
support at least one filesystem. For example, a Unix or Linux platform combines all
mounted
(attachedandprepared)disksintoonevirtualfilesystem.Incontrast,Windows
associates a separate filesystem with each active disk drive.
Java offers access to the platform's available filesystem(s) via its concrete
java.io.File
class.
File
declares the
File[] listRoots()
class method to
return the root directories (roots) of available filesystems as an array of
File
objects.
Note
Thesetofavailablefilesystemrootsisaffectedbyvariousplatform-leveloper-
ations,suchasinsertingorejectingremovablemedia,anddisconnectingorunmounting
physical or virtual disk drives.