-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConcatenate.java
More file actions
74 lines (68 loc) · 1.5 KB
/
Concatenate.java
File metadata and controls
74 lines (68 loc) · 1.5 KB
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
import java.util.*;
import java.io.*;
public class Concatenate
{
private ArrayList<String> inputList = new ArrayList<String>();
private String fileOne;
private String fileTwo;
private String fileOutput;
private boolean checkDump;
public Concatenate(String fileOne, String fileTwo, String fileOutput)
{
this.fileOne = fileOne;
this.fileTwo = fileTwo;
this.fileOutput = fileOutput;
}
public void concate()
{
readIn(this.fileOne);
readIn(this.fileTwo);
readOut(this.inputList, fileOutput);
}
private void readIn(String fileName)
{
Scanner inputStream = null;
try
{
inputStream = new Scanner(new FileReader(fileName));
while (inputStream.hasNextLine())
{
this.inputList.add(inputStream.nextLine());
}
inputStream.close();
checkDump = true;
}
catch (IOException e)
{
System.out.println("File Read Failed");
checkDump = false;
}
}
private void readOut(ArrayList<String> output, String fileName)
{
PrintWriter outputStream = null;
try {
outputStream = new PrintWriter(new FileOutputStream(fileName));
for (String s : output)
{
outputStream.println(s);
}
checkDump = true;
}
catch (IOException e) {
System.out.println("File Write Failed");
checkDump = false;
}
finally {
outputStream.flush();
outputStream.close();
}
}
public String getOutput()
{
if (checkDump == true) {
return (fileOne+" and "+fileTwo+" dumped to "+fileOutput);
}
return (fileOne+" and "+fileTwo+" not dumped to "+fileOutput);
}
}