Hi,
I've written a client-server program, the client inputs data, and the server accepts that data and writes it into a text file(file gets created when program is run). Works fine for a single client, now if I have 2 instances of the client running, i want the server to write the data input by client1 and client2 into the text file, what happens in my program is, client1's data is overwritten by client2's data. please can you help me correct this error.

Thanks,
Rohan.
-------------------------
SocketClient file:

import java.net.*;
import java.io.*;

public class SocketClient {
public static void main(String[] args) {
String host = "localhost";
int port = 19999;
System.out.println("SocketClient initialized");
try {
InetAddress address = InetAddress.getByName(host);
Socket connection = new Socket(address, port);
try {
while(true){
PrintWriter output = new PrintWriter(connection.getOutputStream(),true);
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Query: ");
String lineToBeSent = input.readLine();
output.println(lineToBeSent);
}
}
catch (IOException e) {
System.out.println(e);
}

try{
connection.close();
}catch(IOException e){
System.out.println(e);
}
}
catch (IOException f) {
System.out.println("IOException: " + f);
}

}
}
---------------------------------------------------------
MultipleSocketServer file:

import java.net.*;
import java.io.*;
import java.util.*;

public class MultipleSocketServer implements Runnable {

private Socket connection;
private String TimeStamp;
private int ID;
public static void main(String[] args) {
int port = 19999;
int count = 0;
try{
ServerSocket socket1 = new ServerSocket(port);
System.out.println("MultipleSocketServer Initialized");
while (true) {
Socket connection = socket1.accept();
Runnable runnable = new MultipleSocketServer(connection, ++count);
Thread thread = new Thread(runnable);
thread.start();
}
}
catch (Exception e) {}
}
MultipleSocketServer(Socket s, int i) {
this.connection = s;
this.ID = i;
}
public void run() {

try {
BufferedReader input = new BufferedReader(new InputStreamReader(connection.getInputStream()));
PrintStream out1 =new PrintStream(new FileOutputStream("test.txt"));

while(true) {
String message = input.readLine();
out1.println(message);
out1.println();
System.out.println("Record Added to file");
}
}
catch (IOException e) {
System.out.println(e);
}

finally {
try {
connection.close();
}
catch (IOException e){}
}
}
}