Ho scritto questa classe:
import java.io.*;
class LoggedSysOut {
public LoggedSysOut (String k) throws Exception {
this.newfile(k);
}
public void print(String pr) throws Exception{
System.out.print(pr);
cr2.print(pr);
}
public void println(String pr2) throws Exception{
System.out.println(pr2);
cr2.println(pr2);
}
private void newfile(String h) throws Exception{
File cr=new File(h);
FileOutputStream cr1=new FileOutputStream(cr);
PrintStream cr2=new PrintStream(cr1);
}
private PrintStream cr2;
private FileOutputStream cr1;
private File cr;
}
IL FILE SEGUENTE RICHIAMA ALCUNI METODI DI QUESTA CLASSE:
import java.io.*;
class provaLogged {
public static void main (String [] arg) throws Exception {
LoggedSysOut prova=new LoggedSysOut("filelogged");
prova.print("ciao a tutti");
prova.println("casa");
}}
IL PROBLEMA è CHE QUANDO LO COMPILO MI DA UN ERRORE ALLA RIGA 11 DELLA CLASSE E ALLA RIGA 6 DEL PROGRAMMA CHIAMANTE.
VOLEVO SAPERE SE HO DICHIARATO BENE LE VARIABILI DI ISTANZA, DATO CHE MI DA L'ERRORE OGNI VOLTA CHE RICHIAMA L'"OGGETTO" cr2.
GRAZIE A TUTTI