working with text write text by lines

Solutions on MaxInterview for working with text write text by lines by the best coders in the world

showing results for - "working with text write text by lines"
Ed
16 Jan 2017
1public class FileWriter {
2
3    public void writeLines(List<Employee> employees, BufferedWriter writer) {
4        try {
5            for (String employee : employees) {
6                writer.write(employee.getName() + "," + employee.getYearOfBirth());
7            }
8        } catch (IOException ioe) {
9            throw new IllegalStateException("Can not read file", ioe);
10        }
11    }
12
13    public static void main(String[] args) {
14        List<Employee> employees = List.of(new Employee("John Doe", 1970), new Employee("Jack Doe", 1980));
15        try (BufferedWriter writer = Files.newBufferedWriter(Path.of("data.csv"))) {
16            new FileWriter().writeLines(employees, writer);
17        } catch (IOException ioe) {
18            throw new IllegalStateException("Can not write file", ioe);
19        }
20    }
21}
similar questions
queries leading to this page
working with text write text by lines