读取文本文件,用,
分割数字并将它们全部保存到BigInteger
数组的正确方法是什么?
BigInteger[] a = new BigInteger[1000];
try (Stream<String> stream = Files.lines(Paths.get(filePath))) {
} catch (IOException e) {
e.printStackTrace();
}
可以直接完成,还是应该先将整个文件另存为大String
,然后用流拆分它?
String content = new String(Files.readAllBytes(Paths.get(filePath)));
喜欢这个
BigInteger[] array = stream.map(str -> str.split(",")).flatMap(Arrays::stream).map(BigInteger::new)
.toArray(BigInteger[]::new);