fork download
  1. import java.net.*;
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. public class FileServer {
  6. private static String outputFile;
  7. public FileServer() {
  8. try {
  9. ServerSocket server = new ServerSocket(8888);
  10. System.out.println("Server created.");
  11. System.out.println("Waiting for client to connect…");
  12.  
  13. Socket socket = server.accept();
  14. System.out.println("Connected from Client " + socket.getInetAddress().getHostAddress());
  15.  
  16. DataInputStream inputStream = new DataInputStream(socket.getInputStream());
  17. FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
  18. int input = 0;
  19. while(input != -1) {
  20. input = inputStream.readInt();
  21. fileOutputStream.write(input);
  22.  
  23. }
  24. System.out.println("Transfer successfully!");
  25. }
  26. catch(IOException ioException) {
  27. ioException.printStackTrace();
  28. System.exit(1);
  29.  
  30. }
  31. }
  32. public static void main(String args[]) {
  33. if(args.length < 1) {
  34. System.out.println("USAGE: java FileServer [filename]");
  35. System.exit(1);
  36. }
  37. outputFile = args[0];
  38. new FileServer();
  39. }
  40. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: class FileServer is public, should be declared in a file named FileServer.java
public class FileServer {
       ^
1 error
stdout
Standard output is empty