I am trying to write a stream of custom objects with a nice toString method to a file, line by line. What I have so far is this:
private static void writeToFile(Set<Article> articles, Charset cs, Path path) throws IOException {
try(Writer w =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(path.toFile()), cs))) {
articles.stream().map(Article::toString).forEach(w::write);
} catch(IOException e) {}
I am getting the error Unhandled IOException on w::write, which is strange because I am catching this Exception?
Other point, is it possible to write those objects line by line?