I got the file with following structure:
MES2018-05-24_12:05:58.778 RGH2018-05-24_12:06:27.441 ... PGS2018-05-24_12:08:36.586
Want to parse it into Map with key containing only first three symbols of input string, something like this:
MES=12:05:58.778
But IDE won't compile the code provided below. Is there any right way to do this using stream API?
public Map<String, Date> read(String filePath) {
SimpleDateFormat sdt = new SimpleDateFormat("HH:mm:ss.SSS");
Map<String, Date> mapFromFile = null;
try (Stream<String> stream = Files.lines(Paths.get(filePath))) {
mapFromFile = stream
.map(key -> key.split("_"))
.collect(Collectors.toMap(value -> value[0].replaceAll("[^a-zA-Z]", ""), value -> sdt.parse(value[1])));
} catch (IOException e) {
e.printStackTrace();
}
return mapFromFile;
}