forked from bamberjp/JCSV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSVWriter.java
76 lines (69 loc) · 1.54 KB
/
CSVWriter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* CSVWriter Class
*/
import java.io.File;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
public class CSVWriter {
/**
* BufferedWriter
*
* @var java.io.BufferedWriter
*/
private BufferedWriter Writer;
/**
* Constructor
*
* @param java.io.File Output File.
*
* @throws java.io.IOException If unable to write to the Output File.
*
* @return void
*/
public CSVWriter(File Output) throws IOException {
try {
Writer = new BufferedWriter(new FileWriter(Output));
} catch (IOException e) {
throw e;
}
}
/**
* Writes a row of data to the Output CSV File
*
* @param String[] Array of String data
*
* @throws java.io.IOException If unable to read from Source file.
*
* @return void
*/
public void writeRow(String[] Row) throws IOException {
try {
String sRow = new String("");
for (int i = 0; i < Row.length; i++) {
if (i != Row.length - 1) {
sRow += Row[i] + ",";
} else {
sRow += Row[i] + "\n";
}
}
Writer.write(sRow);
} catch (IOException e) {
throw e;
}
}
/**
* Closes the stream and releases any system resources associated with it.
*
* @throws java.io.IOException If unable to read from Source file.
*
* @return void
*/
public void close() throws IOException {
try {
Writer.close();
} catch (IOException e) {
throw e;
}
}
}