static int transfer(InputStream from, OutpuStream to) throws IOException
{
int transferred = 0;
with(: from ) with(: to ) //both throw an IOException
{
int read;
while( (read = from.read() ) >= 0) //throws IOException
{
to.write((byte) read); //throws IOException
transferred++;
}
return transferred; // returns from enclosingElement == transfer
}
// Compile-Time error: unreachable statement
// because either IOException is re-thrown
// or it will returned from inside the block
out.printf("Bytes transferred: %d\n", transferred);
}