Java Reference
In-Depth Information
to process. The first call instructs the method to process two tokens. It operates on the
first two tokens of the file, generating the following output:
number 1 = 308.2
number 2 = 14.9
Sum = 323.09999999999997
The second call on the method indicates that three tokens are to be processed.
Some people expect the method to process the first three tokens of the file, but that's
not what happens. Remember that the Scanner keeps track of where the input cursor
is positioned. After the first call on the method, the input cursor is positioned beyond
the first two tokens. So the second call on the method processes the next three tokens
from the file, producing the following output:
number 1 = 7.4
number 2 = 2.8
number 3 = 3.9
Sum = 14.1
The final call on the method asks the Scanner to process the next two tokens from
the file, so it ends up processing the sixth and seventh numbers from the file:
number 1 = 4.7
number 2 = 15.4
Sum = 10.7
The program then terminates, never having processed the eighth number in the file.
The key point to remember is that a Scanner keeps track of the position of the
input cursor, so you can process an input file piece by piece in a very flexible manner.
Even when the Scanner is passed as a parameter to a method, it remembers how
much of the input file has been processed so far.
Paths and Directories
Files are grouped into folders , also called directories. Directories are organized in a
hierarchy, starting from a root directory at the top. For example, most Windows
machines have a disk drive known as C: . At the top level of this drive is the root
directory, which we can describe as C:\ . This root directory will contain various top-
level directories. Each top-level directory can have subdirectories, each of which also
has subdirectories, and so on. All files are stored in one of these directories. The
description of how to get from the top-level directory to the particular directory that
stores a file is known as the path of the file.
File Path
A description of a file's location on a computer, starting with a drive and
including the path from the root directory to the directory where the file is
stored.
 
Search WWH ::




Custom Search