×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Boulty Doolin
Added: Nov 11, 2016 12:09 PM
Modified: Nov 11, 2016 12:15 PM
Views: 15
Tags: file text read line
Reads a text file and returns the first line conrtaining a specified string.
  1.         //read file into stream, try-with-resources
  2.         try (Stream<String> stream = Files.lines(Paths.get(fileName))) {
  3.             matchingLine = stream
  4.                     .filter(line -> line.contains(someString))
  5.                     .findFirst()
  6.                     .get();
  7.         }
  8.