Copy Loop

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Answer:

DataInputStream and DataOutputStream

Copy Loop

The core of the program looks like this:

DataInputStream  instr;
DataOutputStream outstr;
. . . .
int data;
while ( true )
{
  data = instr.readUnsignedByte() ;
  outstr.writeByte( data ) ;
}

Repeatedly, one byte at at time is read and written, using the low-order byte of the integer variable data as an intermediate location.

QUESTION 15:

  • How does the loop end?
  • How should this be handled?