code: public void printFile(final File f, final String hostName, final String printerName, final String documentName) throws IOException {
          final byte buffer[] = new byte[1000];
  
          //Send print file
          if (!(f.exists() && f.isFile() && f.canRead()))
              throw new IOException("Error opening print file");
          final ByteArrayOutputStream output = new ByteArrayOutputStream();
          try (FileInputStream fs = new FileInputStream(f)) {
              int readCounter;
              do {
                  readCounter = fs.read(buffer);
                  if (readCounter > 0)
                      output.write(buffer, 0, readCounter);
              } while (readCounter > 0);
              printStream(output, hostName, printerName, documentName);
          }
      }
docs: /*
  Print a file to a network host or printer
  fileName The path to the file to be printed
  hostName The host name or IP address of the print server
  printerName The name of the remote queue or the port on the print server
  documentName The name of the document as displayed in the spooler of the host