code: private static void countFile(String fname) {
      // large buffers pay off
      final int bufSize = 50 * 1024 * 1024;
      try {
        Path path = Paths.get(new URI(fname));
        long size = Files.size(path);
        System.out.println(fname + ": " + size + " bytes.");
        ByteBuffer buf = ByteBuffer.allocate(bufSize);
        System.out.println("Reading the whole file...");
        Stopwatch sw = Stopwatch.createStarted();
        try (SeekableByteChannel chan = Files.newByteChannel(path)) {
          long total = 0;
          int readCalls = 0;
          MessageDigest md = MessageDigest.getInstance("MD5");
          while (chan.read(buf) > 0) {
            readCalls++;
            md.update(buf.array(), 0, buf.position());
            total += buf.position();
            buf.flip();
          }
          readCalls++; // We must count the last call
          long elapsed = sw.elapsed(TimeUnit.SECONDS);
          System.out.println(
              "Read all "
                  + total
                  + " bytes in "
                  + elapsed
                  + "s. "
                  + "("
                  + readCalls
                  + " calls to chan.read)");
          String hex = String.valueOf(BaseEncoding.base16().encode(md.digest()));
          System.out.println("The MD5 is: 0x" + hex);
          if (total != size) {
            System.out.println(
                "Wait, this doesn't match! We saw "
                    + total
                    + " bytes, "
                    + "yet the file size is listed at "
                    + size
                    + " bytes.");
          }
        }
      } catch (Exception ex) {
        System.out.println(fname + ": " + ex.toString());
      }
    }
docs: Print the length of the indicated file.
  
  <p>This uses the normal Java NIO Api, so it can take advantage of any installed NIO Filesystem
  provider without any extra effort.