Question: Write a file searching program that uses streams to efficiently search a set of files for a given substring. Write two versions of the code,
Write a file searching program that uses streams to efficiently search a set of files for a given substring. Write two versions of the code, one that sequentially reads each file with a Scanner and checks each line to see if it contains the substring, and a second that uses streams to open all of the files and search the lines using stream operations. The most efficient version of the stream code will open all of the files in parallel. Test how much more efficient the streams are than the Scanner by using System.currentTimeMillis to measure the elapsed time for both versions of the code when run on a collection of large files, printing output such as the following:

Searching 15 files for "the" using Scanner: there were 84530 total matching lines. Took 546 ms. Searching 15 files for "the" using streams: there were 84530 total matching lines. Took 160 ms.
Step by Step Solution
3.39 Rating (158 Votes )
There are 3 Steps involved in it
import javaio public class ReadFromFile2 public static void mainString argsthrows Exception We need ... View full answer
Get step-by-step solutions from verified subject matter experts
