import java.io.*;
public class BinaryFileTest2 {
  public static void main(String[] args) 
                     throws Exception {
    File testFile = new File("t1.jpg");
    FileInputStream fIn = new FileInputStream(testFile);
    int size = (int) testFile.length();
    long read = 0;
    int n, r;
    byte[] data = new byte[size];
    while (read < size) {
      n = fIn.available();
      if (n > 10000) n = 10000;
      r = fIn.read(data, (int)read, n);
      read += r;
    }
    System.out.println("Read " + read + " bytes");
    testFile = new File("t1copy.jpg");
    FileOutputStream fOut = new FileOutputStream(testFile);
    fOut.write(data);
    fOut.close();
  }
}