Writing Data to a Stream
In the java.io
package, the classes for working with streams come in matched sets. There are FileInputStream
and FileOutputStreams
classes for working with byte streams, FileReader
and FileWriter
classes for working with character streams, and many other sets for working with other kinds of stream data.
To begin writing data, you first create a File
object that is associated with an output stream. This file doesn’t have to exist on your system.
You can create a FileOutputStream
in two ways. If you want to append bytes onto an existing file, call the FileOutputStream()
constructor method with two arguments: a File
object representing the file and the boolean
of true
. The bytes you write to the stream are tacked onto the ...
Get Sams Teach Yourself Java™ in 24 Hours, Sixth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.