]> git.somenet.org - pub/jan/lsdc.git/blob - src/main/java/at/ac/tuwien/lsdc/util/CSVHandler.java
Added CSV handler for reading and writing CSV-Files
[pub/jan/lsdc.git] / src / main / java / at / ac / tuwien / lsdc / util / CSVHandler.java
1 package at.ac.tuwien.lsdc.util;
2
3 import java.io.FileReader;
4 import java.io.FileWriter;
5 import java.io.IOException;
6 import java.util.List;
7
8 import au.com.bytecode.opencsv.CSVReader;
9 import au.com.bytecode.opencsv.CSVWriter;
10
11 public class CSVHandler {
12         private final String filename;
13
14         public CSVHandler(String filename) {
15                 this.filename = filename;
16         }
17
18         public List readFile() throws IOException {
19                 CSVReader reader = new CSVReader(new FileReader(filename));
20                 return reader.readAll();
21         }
22
23         public void writeFile(List data) throws IOException {
24                 CSVWriter writer = new CSVWriter(new FileWriter(filename), '\t');
25                 writer.writeAll(data);
26                 writer.close();
27         }
28
29         public void writeLine(String[] data) throws IOException {
30                 CSVWriter writer = new CSVWriter(new FileWriter(filename), '\t');
31                 writer.writeNext(data);
32                 writer.close();
33         }
34 }