В консоли и в файле вижу одно и то же, но валидатор не принимает.
package com.javarush.task.task19.task1917;
/*
Свой 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(String fileName) throws IOException {
fileWriter = new FileWriter(fileName);
}
public FileConsoleWriter(String fileName, boolean append) throws IOException {
fileWriter = new FileWriter(fileName, append);
}
public FileConsoleWriter(File file) throws IOException {
fileWriter = new FileWriter(file);
}
public FileConsoleWriter(File file, boolean append) throws IOException {
fileWriter = new FileWriter(file, append);
}
public FileConsoleWriter(FileDescriptor fd) {
fileWriter = new FileWriter(fd);
}
public void write(char[] cbuf, int off, int len) throws IOException {
for (int i=off; i<=cbuf.length - len; i++) {
System.out.print(cbuf[i]);
}
fileWriter.write(cbuf, off, len);
}
public void write(int c) throws IOException {
System.out.print((char) c);
fileWriter.write(c); //???
}
public void write(String str) throws IOException {
System.out.print(str);
fileWriter.write(str);
}
public void write(String str, int off, int len) throws IOException {
System.out.print(str.substring(off, str.length() - len));
fileWriter.write(str, off, len);
}
public void write(char[] cbuf) throws IOException {
for (int i=0; i<cbuf.length; i++) {
System.out.print(cbuf[i]);
}
fileWriter.write(cbuf);
}
public void close() throws IOException {
fileWriter.close();
}
public static void main(String[] args) throws IOException {
FileConsoleWriter fcw = new FileConsoleWriter("c:\\tmp\\data.txt");
fcw.write(new char[]{'q', 'w', 'e', 'r', 't', 'y'});
fcw.write("\r\n");
fcw.write("NewString");
fcw.write("\r\n");
fcw.write(2_000_000_000);
fcw.write("\r\n");
fcw.write(new char[]{'q', 'w', 'e', 'r', 't', 'y', '1', '2', '3'}, 2, 4);
fcw.write("\r\n");
fcw.write("Qwerty123!", 2, 4);
fcw.close();
}
}