ungureanuvladvictor

Untitled

Dec 6th, 2013
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. package com.vungueanu;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.net.ServerSocket;
  6. import java.net.Socket;
  7.  
  8. public class Main {
  9.  
  10. static final int PORT = 4444;
  11. static File directory = null;
  12. static ServerSocket listener = null;
  13. static Socket connection = null;
  14.  
  15. public static void main(String[] args)
  16. throws IOException {
  17.  
  18. if (args.length == 0) {
  19. System.out.println("Usage: java FileServer <dir>\n");
  20. return;
  21. }
  22.  
  23. directory = new File (args[0]);
  24. if (!directory.exists()) {
  25. System.out.println ("Folder doesn't exist!");
  26. return;
  27. }
  28.  
  29. if (!directory.isDirectory()) {
  30. System.out.println("Not a folder!\n");
  31. return;
  32. }
  33.  
  34. listener = new ServerSocket (PORT);
  35.  
  36. while (true) {
  37. connection = listener.accept();
  38. new doComms (directory, connection);
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment