/media/sda-magnetic/david/Dok-15-2023-11-27/fernuni-hagen/cs-i-ii/old-cs-2-03/java-new/2021-01-08/xyz.java


import java.io.*;
import java.net.Socket;

public class SimpleFileClient {
    
    public final static int SERVER_PORT = 8181;
    
    public static void main (String [] args) throws IOException {
        String host = args [0];
        String fileNameAtServer = args [1];
        String fileNameAtClient = args [2];
        
        try {
            Socket sock = new Socket (host, SERVER_PORT);
            BufferedOutputStream toFile = new BufferedOutputStream (new FileOutputStream(fileNameAtClient));
                
            BufferedWriter toServer = new BufferedWriter (new OutputStreamWriter (sock.getOutputStream (), "UTF-8"));
                
            String command = "GET " + fileNameAtServer;
            toServer.write (command + "\n");
            toServer.flush ();
                
            BufferedInputStream fromServer = new BufferedInputStream (sock.getInputStream ());
                
            int data = -1;
            while ((data = fromServer.read ()) != -1) {
                toFile.write (data);
            }
            toFile.flush ();
        }
        catch (FileNotFoundException e) {
            System.out.println ();
            System.out.println ("Datei kann nicht geschrieben werden: " + e.getMessage ());
        }
        catch (IOException e) {
            System.out.println (e);
        }
    }
}