...in my environnement only
package fr.codegym.task.task19.task1917;
/*
Ton propre FileWriter
*/
import java.io.*;
public class FileConsoleWriter {
public static void main(String[] args) throws IOException {
/*
FileConsoleWriter test = new FileConsoleWriter("c:/temp/consolewriter.txt");
test.write("coucou");
test.write("coucou",2,4);
test.write(48);
test.write( new char[]{'a','b','c'} );
test.write( new char[]{'a','b','c'},1,1 );
test.close();
*/
}
private FileWriter fileWriter;
private PrintWriter console = new PrintWriter(System.out);
public FileConsoleWriter(String fileName) throws IOException {
this.fileWriter = new FileWriter(fileName);
}
public FileConsoleWriter(String fileName, boolean append) throws IOException {
this.fileWriter = new FileWriter(fileName, append);
}
public FileConsoleWriter(File file) throws IOException {
this.fileWriter = new FileWriter(file);
}
public FileConsoleWriter(File file, boolean append) throws IOException {
this.fileWriter = new FileWriter(file, append);
}
public FileConsoleWriter(FileDescriptor fd) {
this.fileWriter = new FileWriter(fd);
}
public void write(char[] cbuf, int off, int len) throws IOException {
this.fileWriter.write(cbuf, off, len);
this.console.write(cbuf, off, len);
}
public void write(int c) throws IOException {
this.fileWriter.write(c);
this.console.write(c);
}
public void write(String str) throws IOException {
this.fileWriter.write(str);
this.console.write(str);
}
public void write(String str, int off, int len) throws IOException {
this.fileWriter.write(str,off,len);
this.console.write(str,off,len);
}
public void write(char[] cbuf) throws IOException {
this.fileWriter.write(cbuf);
this.console.write(cbuf);
}
public void close() throws IOException {
this.fileWriter.flush();
this.fileWriter.close();
this.console.flush();
this.console.close();
}
}