Class data outputstream

354 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
354
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Class data outputstream

  1. 1. Class DataOutputStream DataOutputStream
  2. 2. DataOutputStream • A data output stream lets an application write primitive Java data types to an output stream in a portable way. An application can then use a data input stream to read the data back in. DataOutputStream
  3. 3. java.io.DataOutputStream public class DataOutputStream extends OutputStream implements DataOutput DataOutputStream
  4. 4. DataOutputStream constructor • DataOutputStream(OutputStream out) • Creates a new data output stream to write data to the specified underlying output stream. DataOutputStream
  5. 5. writeUTF() • Writes a string to the underlying output stream using UTF-8 encoding in a machineindependent manner. DataOutputStream
  6. 6. writeUTF() • public final void writeUTF(String str) throws IOException • First, two bytes are written to the output stream as if by the writeShort method giving the number of bytes to follow. This value is the number of bytes actually written out, not the length of the string. Following the length, each character of the string is output, in sequence, using the UTF-8 encoding for the character. DataOutputStream
  7. 7. writeBoolean() • Writes a boolean to the underlying output stream as a 1-byte value. The value true is written out as the value (byte)1; the value false is written out as the value (byte)0. DataOutputStream
  8. 8. writeBoolean() syntax public final void writeBoolean(boolean v) throws IOException DataOutputStream
  9. 9. writeInt() • Writes an int to the underlying output stream as four bytes, high byte first • public final void writeInt(int v) throws IOException DataOutputStream
  10. 10. Flush() • Flushes this data output stream. This forces any buffered output bytes to be written out to the stream.The flush method of DataOutputStream calls the flush method of its underlying output stream. • public void flush() throws IOException DataOutputStream
  11. 11. Close() • Closes this output stream and releases any system resources associated with the stream.The close method calls its flush method, and then calls the close method of its underlying output stream. • public void close() throws IOException DataOutputStream

×