Java Reference
In-Depth Information
public void write(char [] c,int offset, int length). Writes length number
of characters in the array starting at the index specified by offset.
public void write(String s). Writes the given String to the stream.
public void write(String s, int offset, int length).
Writes the specified
subset of the given String to the stream.
The child classes of Writer implement the write() methods in their own
unique ways. For example, the PipedWriter class writes the characters to a
pipe (a stream between two threads), and the OutputStreamWriter class con-
verts the writer into an output stream, converting the characters into bytes.
The Reader Class
The Reader class is the parent of all the reader classes in the java.io package. The
Reader class has a close() and skip() method similar to the ones in InputStream. It
also contains read() methods that correspond to the write() methods in Writer:
public int read(). Reads a single character from the stream.
public int read(char [] c). Reads in a collection of characters and places
them in the given array. The return value is the actual number of characters
read.
public int read(char [] c, int offset, int length). Reads in a collection of
characters and places them into the specified portion of the array.
For each Writer class, there is a corresponding Reader class.
The java.io.File class
The java.io.File class is a utility class for working with files and directories. It is not a stream
class and cannot be used for performing any I/O. However, it is widely used by the other
classes in the java.io package.
Think of a File object as a String representing the name and location of a file or directory.
The File class has four constructors:
public File(String pathname). Creates a File object associated with the file or
directory specified by pathname.
public File(String parent, String child). Creates a File object using the given para-
meters. The parent parameter represents a directory, and the child parameter rep-
resents a subdirectory or file located within parent.
public File(File parent, String child). Similar to the previous constructor, except
that the directory is denoted by a File object instead of a String.
public File(URI uri). Creates a File object using the given java.net.URI object. A URI
is a uniform resource identifier. A file URI is of the format file:/// directory / filename .
Search WWH ::




Custom Search