123456789101112131415161718192021222324252627282930313233343536 |
- package csv;
- import java.io.FileWriter;
- import java.io.IOException;
- public class CSVWriter {
- FileWriter writer;
- char separator;
- boolean newline = true;
- public CSVWriter(String filename, char separator) throws IOException {
- this.writer = new FileWriter(filename);
- this.separator = separator;
- }
- public void write(String record) throws IOException {
- if (!newline) {
- this.writer.append(this.separator);
- } else {
- this.newline = false;
- }
- this.writer.append(record);
- }
- public void writeln() throws IOException {
- this.writer.append('\n');
- this.newline = true;
- }
- public void close() throws IOException {
- this.writer.flush();
- this.writer.close();
- }
- }
|