Please what am I doing wrong?
The mentor says:
1. Be sure that the FileConsoleWriter class's write(char[] cbuf, int off, int len) throws IOException method also writes the data to the console.
2. Be sure that the FileConsoleWriter class's write(String str, int off, int len) throws IOException method calls the corresponding method on fileWriter.
package com.codegym.task.task19.task1917;
/*
Your own FileWriter
*/
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileWriter;
import java.io.IOException;
public class FileConsoleWriter {
private FileWriter fileWriter;
public FileConsoleWriter(File file) throws IOException {
this.fileWriter = new FileWriter(file);
}
public FileConsoleWriter(String fileName) throws IOException {
this.fileWriter = new FileWriter(fileName);
}
public FileConsoleWriter(FileDescriptor fd) {
this.fileWriter = new FileWriter(fd);
}
public FileConsoleWriter(String fileName, boolean append) throws IOException {
this.fileWriter = new FileWriter(fileName, append);
}
public FileConsoleWriter(File file, boolean append) throws IOException {
this.fileWriter = new FileWriter(file, append);
}
public void write(int c) throws IOException {
fileWriter.write(c);
System.out.println(c);
}
public void write(String str) throws IOException {
fileWriter.write(str);
System.out.println(str);
}
public void write(String str, int off, int len) throws IOException {
this.fileWriter.write(str, off, len);
System.out.println(str.substring(off, len+1));
}
public void write(char[] cbuf, int off, int len) throws IOException {
fileWriter.write(cbuf, off, len);
for (int i = 0; i < len; i++)
System.out.println(cbuf[off + i]);
}
public void write(char[] cbuf) throws IOException {
fileWriter.write(cbuf);
for (char c : cbuf)
System.out.print(c);
}
public void close() throws IOException {
fileWriter.close();
}
public static void main(String[] args)throws IOException {
FileConsoleWriter f = new FileConsoleWriter("file.txt");
char[] d = {48, 49, 50, 51, 52, 53};
String s = "So write this only";
f.write(d,1, 4);
}
}