我需要更改代码才能流式传输。应该只有7行代码。
- Use
Files.lines()
to read file as stream - Filter out lines which are not matching pattern "only whitespaces and numbers"
- Use map operation which will inside split the line by whitespace and convert that to stream (
Arrays.stream()
can be useful, then use reduce operation to get numbers concatenated with "+", then use the same trick as above to calculate the sum of numbers and concatenate it with above string) - Write each line to a file - just using
PrintWriter
andforEach
or useFiles.write()
method