This question has already been answered:

The file contains two numbers, say 5 and 8, and then comes a two-dimensional matrix. How on the basis of these numbers, to count a certain number of characters of this matrix? Suppose in this case you need to consider a matrix of 5 by 8. And all that to skip after it

Marked as a duplicate by participants Vladimir Martyanov , aleksandr barakin , user194374, Denis , dirkgntly Aug 25 '16 at 9:52 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • one
    And what exactly are the problems? In reading a certain number of bytes from a file? - Vladimir Martyanov
  • @ Vladimir Martiyanov Fixed the question a little - Kirill Avdeev
  • It's still not clear what the problem is: in reading a certain number of bytes from a file? Or what? - Vladimir Martyanov
  • @ Vladimir Martiyanov yes, how can I read a certain number of bytes - Kirill Avdeev
  • four

1 answer 1

Try this:

try (BufferedReader reader = Files.newBufferedReader(Paths.get(fileName))) { String[] params = reader.readLine().split(" "); int n = Integer.parseInt(params[0]); int m = Integer.parseInt(params[1]); System.out.println(n + "x" + m); reader .lines() .limit(m) .forEach(System.out::println); }