summaryrefslogtreecommitdiffstats
path: root/io/WriteFile.java
diff options
context:
space:
mode:
Diffstat (limited to 'io/WriteFile.java')
-rw-r--r--io/WriteFile.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/io/WriteFile.java b/io/WriteFile.java
new file mode 100644
index 0000000..454b567
--- /dev/null
+++ b/io/WriteFile.java
@@ -0,0 +1,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();
+ }
+} \ No newline at end of file