I have a CSV file, and the first line contains the headers. So I thought it would be ideal to use Java 8 threads.
try (Stream<String> stream = Files.lines(csv_file) ){
stream.skip(1).forEach( line -> handleLine(line) );
} catch ( IOException ioe ){
handleError(ioe);
}
Is it possible to take the first element, parse it, and then call the forEach method? Sort of
stream
.forFirst( line -> handleFirst(line) )
.skip(1)
.forEach( line -> handleLine(line) );
OPTIONAL: My CSV file contains about 1 thousand lines, and I can process each line in parallel to speed it up. Except the first line. I need the first line to initialize other objects in my project: / So, maybe quickly open the BufferedReader, read the first line, close the BufferedReader and use parallel streams?
source
share