public @ Nonnull String head ( int numChars ) throws IOException { char [ ] buf = new char [ numChars ] ; int read = 0 ; try ( Reader r = new FileReader ( file ) ) { while ( read < numChars ) { int d = r . read ( buf , read , buf . length - read ) ; if ( d < 0 ) break ; read += d ; } return new String ( buf , 0 , read ) ; } }
Reads the first N characters or until we hit EOF .