
import java.io.IOException;
import java.io.FileNotFoundException;

public class Dateien {


    public static void main(String[] args) {

        Screen sc = new Screen();

        if ( args.length < 1 ) {
	    sc.println("Usage: Dateien <eingabe datei> [<ausgabe datei>]");
            return;
	}

        DateiEin rein;
        try {
	    rein = new DateiEin(args[0]);
	}
        catch (FileNotFoundException e) {
            sc.println("Die Datei " + args[0] + " existiert nicht.");
            return;
	}

        DateiAus raus = null;

        if ( args.length >= 2 ) {
            try {
	        raus = new DateiAus(args[1]);
            }
            catch (IOException e) {
                sc.println("Die Datei " + args[1] + " ist nicht beschreibar.");
                return;
            }
	}
 
        String ea = "";

	try {
        do {
            ea = rein.readLine();
            if ( ea == null ) break; 
            if ( raus != null ) {
               raus.println(ea);
	    } else {
               sc.println("Eingabe ist = " + ea);
	    }
	} while ( !ea.equals("ende") );
	}
        catch (IOException e) {
            e.printStackTrace();
	}
	try {
	    rein.close();
	    raus.close();
	}
	catch (IOException e) {
            e.printStackTrace();
	}

    }


}
