I'm trying to create a simple Client-Server java program. Simple, I need to send a text file (ToSend.txt) from the Server to the client, it's in the same directory where the Server.java is. After running the program, the ToSend.txt file should be in the same directory where the Client.java is, and will be renamed as Received.txt.
Server:
File file = new File("ToSend.txt");
try
{
ServerSocket serverSocket = new ServerSocket(1234);
Socket serverEndpoint = serverSocket.accept();
//what to do here?
serverEndpoint.close();
}
catch (Exception e)
{
e.printStackTrace();
}
Client:
try
{
Socket clientEndpoint = new Socket(localhost, 1234);
//what to do here?
clientEndpoint.close();
}
catch (Exception e)
{
e.printStackTrace();
}
ToSend.txt
Self-learning during a global pandemic is difficult.
I got confused if I will use DataOutputStream or just OutputStream or FileReader, i need help.