This block could be extracted in a function that takes a Reader or BufferedReader and a line_count and prints the given amount of lines, so you wouldn't need to have it twice (once here, once in read_and_print)