-
Notifications
You must be signed in to change notification settings - Fork 0
/
OutputWriter.java
44 lines (39 loc) · 1009 Bytes
/
OutputWriter.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
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
/**
* Class for writing information to a file.
*
* @author (Per Lauvås & Tor-Morten Grønli)
* @version (2.0)
*/
public class OutputWriter
{
/**
* Constructor for objects of class OutputWriter
*/
public OutputWriter()
{
}
/**
* Writes a list of words to a file. The words are separated by the 'space' character.
*
* @param output the list of words
* @param filename the name of the output file
*/
public void write(ArrayList<String> output, String filename)
{
try {
FileWriter out = new FileWriter(filename);
for(String word : output) {
out.write(word + " ");
}
out.close();
}
catch(IOException exc) {
System.out.println("Error writing output file: " + exc);
}
}
}