Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- import java.util.Scanner;
- class TCPServer
- {
- public static void main(String[] args) throws Exception{
- ServerSocket serverSocket = new ServerSocket(4000);
- System.out.println("Server Ready for Connection");
- Socket sock = serverSocket.accept();
- System.out.println("Connection was successful");
- InputStream istream = sock.getInputStream();
- Scanner sc=new Scanner(new InputStreamReader(istream));
- String fname=sc.nextLine();
- Scanner sc1=new Scanner(new FileReader(fname));
- OutputStream ostream = sock.getOutputStream();
- PrintWriter pw = new PrintWriter(ostream,true);
- String str;
- while(sc1.hasNext())
- {
- str=sc1.nextLine();
- pw.println(str);
- }
- System.out.println("File Content Sent Sucessfully");
- sock.close();
- serverSocket.close();
- pw.close();
- sc.close();
- sc1.close();
- }
- }
Add Comment
Please, Sign In to add comment