package biblioteki.csv;

import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.util.List;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;

public class Zapis2 {

	public static void main(String[] args) {
		System.out.println("Zaczynamy...");
		
		List<String> lista = List.of("Jan", "Kowalski", "brak danych");

		CSVFormat format = CSVFormat.EXCEL
				.withDelimiter(';')
				.withHeader("imię", "nazwisko", "wiek", "waga");
		try(PrintWriter out = new PrintWriter("b.csv", Charset.forName("windows-1250"));
			CSVPrinter printer = new CSVPrinter(out, format)) {
			printer.printRecord("Ala", "Kowalska", 30, 3.14);
			printer.printRecord("Łucja", "Kowalska", 40, new BigDecimal("123.45"));
			printer.printComment("komentarz");
			printer.printRecord(lista);
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		System.out.println("Gotowe");
	}

}
