summaryrefslogtreecommitdiffstats
path: root/io/WriteFile.java
blob: 454b56793327883d234f3c767839032999a3f634 (plain) (blame)
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
package scruf.io;

import java.io.*;

public class WriteFile {
    private File outputFile;
    private String content;
    public WriteFile(File outputFile, String content) {
	this.outputFile = outputFile.getAbsoluteFile();
	this.content = content;
    }
    public void write() {
	try {
	    System.out.println("Writing..."+outputFile.getName());
	    BufferedWriter bwriter = new BufferedWriter
		(new FileWriter(outputFile));
	    // write content to file.
	    bwriter.write(content);
	    bwriter.close();
	}catch(IOException e) {
	    System.err.println("Error occured while writing"+
			       " file : "+outputFile);
	}
    }
    public void append() {
	StringBuilder sbuilder = new StringBuilder(
						   new ReadFile(outputFile).getContent());
	sbuilder.append(content);
	// new content
	content = sbuilder.toString();
	write();
    }
}