Java Reference
In-Depth Information
c and c+ : Open a file for writing only or for reading and writing (pointer at beginning of file);
if file does not exist, try to create it; existing files will not be made empty, as opposed to
w/w+ , which means that writing data will overwrite existing data.
Don't panic if this list seems a bit daunting or confusing, as the most important thing for now is to
remember that files can be opened for reading and writing. For writing, it is important to keep in
mind that you can either empty an existing file and rewrite over it or keep the existing file in tact
and append your data to the end. The reason why you don't need to remember the full list of file
modes is because the Java file API makes things simple, as you'll see later.
The second general concept we highlight here is the difference between text and binary files. All the
files on your computer can be categorized into these two formats. The difference lies in how the file
encodes the data it contains. At the most basic level, both text and binary files store data as a series
of bits (a series of zeroes and ones). However, in a text file, the bits represent characters (numbers,
spaces, letters, etc.), while in a binary file, the bits represent custom data, stored and interpreted
according to a particular format.
When you create a .txt file using Windows Notepad, for instance, you are creating a text file. Figure
8-1 illustrates a simple text file containing two lines of text opened in Notepad. On the right side,
you can see this file in its hexadecimal representation—a compact representation of the bits stored in
the file. As you can see, each byte (two hexadecimal characters) maps to exactly one character—54
maps to T and 73 maps to s.
fiGure 8-1
character encodinG
You might be wondering how exactly your computer knows which byte (a series of
eight zeroes and ones) should be mapped to which character. The answer lies in the
concept of standardization. As with every standardization process, many standards
exist, all of which are compatible with one another to varying degrees (ranging from
fully backward-compatible to completely incompatible). In western regions, this
continues
 
Search WWH ::




Custom Search