forked from mrhappyasthma/MiniJava-Compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinker.java
More file actions
71 lines (61 loc) · 1.2 KB
/
Copy pathLinker.java
File metadata and controls
71 lines (61 loc) · 1.2 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
//Mark Klara
//mak241@pitt.edu
//CS 1622 - Project 3
//Linker.java
package linker;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.FileNotFoundException;
public class Linker
{
private String inFile;
private String outFile;
public Linker()
{
inFile = null;
outFile = null;
}
public Linker(String input, String output)
{
inFile = input;
outFile = output;
}
public void link()
{
try
{
if(inFile == null)
{
System.err.println("Input file for the linker is invalid.");
return;
}
if(outFile == null)
{
System.err.println("Output file for the linker is invalid.");
return;
}
FileReader fr = new FileReader(inFile);
BufferedReader br = new BufferedReader(fr);
FileWriter fw = new FileWriter(outFile, true);
BufferedWriter bw = new BufferedWriter(fw);
String temp;
while((temp = br.readLine()) != null)
{
bw.write(temp, 0, temp.length());
bw.write("\n", 0, 1);
}
//Close resources
if(br != null)
br.close();
if(bw != null)
bw.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}