Java Reference
In-Depth Information
InputStream subclasses such as ByteArrayInputStream support marking
thecurrentreadpositionintheinputstreamviathe mark() method,andlaterreturnto
that position via the reset() method.
Caution Don'tforgettocall markSupported() tofindoutifthestreamsubclass
supports mark() and reset() .
FileOutputStream and FileInputStream
Files are common stream destinations and sources. The concrete FileOut-
putStream class lets you write a stream of bytes to a file; the concrete FileIn-
putStream class lets you read a stream of bytes from a file.
FileOutputStream subclasses OutputStream and declares five constructors
for creating file output streams. For example, FileOutputStream(String
name) creates a file output stream to the existing file identified by name . This con-
structorthrows FileNotFoundException whenthefiledoesn'texistandcannotbe
created,itisadirectoryratherthananormalfile,orthefilecannotbeotherwiseopened
for output.
The following example uses FileOutputStream(String name) to create a
file output stream with employee.dat as its destination:
FileOutputStream
fos
=
new
FileOut-
putStream("employee.dat");
Tip FileOutputStream(String name) overwrites an existing file. To ap-
pend data instead of overwriting existing content, call a FileOutputStream con-
structorthatincludesa boolean append parameterandpass true tothisparamet-
er.
Search WWH ::




Custom Search