Java 8 Stream – Reading text file line by line

In Java 8, we can use Files.lines to read text (or csv file etc ) file as Stream. Suppose we have sample file FlightDetail.txt containing flight number, flight name, departure airport and airport city details line by line.

1. Reading Text File Using Java 8 Stream


2. Read Text File + Perform Extra Operation + Java 8 Stream

This example will show you how to use Stream to filter content on the basis of some business requirement like filtering out airport present only in Dubai and Munich city, and then convert the entire filtered flight result content to upper case and finally return result as a List.


Check References:

Leave a Reply