I'm trying to read a huge file and extract the text within "quotes" and put the lines into a set and write the content of the set to a file using Java 8 Stream
.
public class DataMiner {
private static final Pattern quoteRegex = Pattern.compile("\"([^\"]*)\"");
public static void main(String[] args) {
String fileName = "c://exec.log";
try (Stream<String> stream = Files.lines(Paths.get(fileName))) {
Set<String> dataSet = stream.
//How do I Perform pattern match here
.collect(Collectors.toSet());
Files.write(Paths.get(fileName), dataSet);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Please help me. Thanks!
EDIT: Answers to the questions..
- No there are no multiple quoted texts.
- I could have used simple loop. But I want to use Java 8 streams