Read .txt file into 2D Array

前端 未结 4 1656
甜味超标
甜味超标 2020-11-28 12:21

There are a few of these topics out there, but this problem has a slight twist that makes it different.

I\'m focused on only half of a larger problem. I\'m sure man

4条回答
  •  日久生厌
    2020-11-28 12:49

    With Java 8 and it's Streams:

      static public int[][] create2DIntMatrixFromFile(Path path) throws IOException {
        return Files.lines(path)
          .map((l)->l.trim().split("\\s+"))
          .map((sa)->Stream.of(sa).mapToInt(Integer::parseInt).toArray())
          .toArray(int[][]::new);
      }
    

    This is just for the 'reading' part of the question.

提交回复
热议问题