All working, able to be built to .jar

This commit is contained in:
2021-11-12 10:41:44 -06:00
parent d39fdbee3b
commit e15cbc6672
21 changed files with 1003 additions and 12 deletions

View File

@@ -0,0 +1,38 @@
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.List;
public class CellFileWriter {
private String[] headers = {"Alpha", "Beta"};
List<Integer[]> cells;
String filename;
public CellFileWriter(String filename, CellSample cells) {
if(!filename.matches(".*\\.csv")){
filename = filename + ".csv";
}
this.filename = filename;
this.cells = cells.getCells();
}
public void writeCellsToFile() {
CSVFormat cellFileFormat = CSVFormat.Builder.create()
.setHeader(headers)
.build();
try(BufferedWriter writer = Files.newBufferedWriter(Path.of(filename), StandardOpenOption.CREATE_NEW);
CSVPrinter printer = new CSVPrinter(writer, cellFileFormat);
){
printer.printRecords(cells);
} catch(IOException ex){
System.out.println("Could not make new file named "+filename);
System.err.println(ex);
}
}
}