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);
}
}
}