From ed2e34ebad8447857ff97fcbcecb0cbed4f4ebdc Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Thu, 2 May 2013 15:46:20 +0200 Subject: [PATCH] Added CSV handler for reading and writing CSV-Files --- .../at/ac/tuwien/lsdc/util/CSVHandler.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/at/ac/tuwien/lsdc/util/CSVHandler.java diff --git a/src/main/java/at/ac/tuwien/lsdc/util/CSVHandler.java b/src/main/java/at/ac/tuwien/lsdc/util/CSVHandler.java new file mode 100644 index 0000000..092345c --- /dev/null +++ b/src/main/java/at/ac/tuwien/lsdc/util/CSVHandler.java @@ -0,0 +1,34 @@ +package at.ac.tuwien.lsdc.util; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; + +import au.com.bytecode.opencsv.CSVReader; +import au.com.bytecode.opencsv.CSVWriter; + +public class CSVHandler { + private final String filename; + + public CSVHandler(String filename) { + this.filename = filename; + } + + public List readFile() throws IOException { + CSVReader reader = new CSVReader(new FileReader(filename)); + return reader.readAll(); + } + + public void writeFile(List data) throws IOException { + CSVWriter writer = new CSVWriter(new FileWriter(filename), '\t'); + writer.writeAll(data); + writer.close(); + } + + public void writeLine(String[] data) throws IOException { + CSVWriter writer = new CSVWriter(new FileWriter(filename), '\t'); + writer.writeNext(data); + writer.close(); + } +} -- 2.43.0