I have a text file like this:
ids.txt
1000
999
745
123
...
I want to read this file and load it in a two dimension
Your last line should probably be size -> new Object[size]
, but you would need to provide arrays of Integers of size one and you would also need to parse the strings into Integers.
I suggest the following:
try (Stream idsStream = Files.lines(idsFile.toPath(), StandardCharsets.US_ASCII)) {
Object[][] ids = idsStream
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(Integer::valueOf)
.map(i -> new Integer[] { i })
.toArray(Object[][]::new);
// Process ids array here...
}