Java Quick Reference
  Language Fundamentals
  Operators and Assignments
  Flow Control and Exceptions
  Declarations and Access Control
  Garbage Collection
  Overloading and Overriding
  Threads
  The java.lang Package
  The java.util Package
  The java.awt Package
  The java.io Package
  References
  Miscellaneous Notes
  Tips & Traps
  Mock Exams

The java.io Package - Data Input and Output

  • DataInputStream and DataOutputStream, like all filters, must be attached to some other stream
  • DataInputStream implements DataInput and has one ctor
    DataInputStream(InputStream in)
  • DataOutputStream implements DataOutput has one ctor
    DataOutputStream(OutputStream out)
    and one field written which contains the number of bytes written.
    Note: if this overflows it is set to Integer.MAX_VALUE.
  • DataInputStream has specialized read() methods, and DataOutputStream, specialized write() methods to handle the various primitive types and UTF-8 characters
DataInputStream Methods DataOutputStream Methods
  write(int oneByte)
read(byte[] buf)
read(byte[] buf, int offset, int count)
write(byte[] buf)
write(byte[] buf, int offset, int count)
readBoolean() writeBoolean(boolean b)
readByte() writeByte(int val)
  writeBytes(String str)
readChar() writeChar(int val)
  writeChars(String str)
readDouble() writeDouble(double val)
readFloat() writeFloat(float val)
readFully(byte[] buf)
readFully(byte[] buf, int offset, int count)
 
readInt() writeInt(int val)
readLine()  
readLong() writeLong(long val)
readShort() writeShort(int val)
readUnsignedByte()  
readUnsignedShort()  
readUTF() writeUTF(String str)
skipBytes()  
Items in red are deprecated.
All the methods throw IOException

Source Code for Examples



Pkg Overview Data Streams Character Streams Byte Streams File Class Readers & Writers
Filter Streams Data Input/Output Reading & Writing Files Serialization