I have a working system here which communicates my android client to my Java Server. Basically it just send a message by my android client and my server receives it by System.out.println(message);
. Now what I want to happen is to save all receives message to a single textfile that will serve as my logs and it will update as soon as my server receives a new message.
while ((message = bufferedReader.readLine()) != null) {
System.out.println("Message from " + message + " at " + dateFormat.format(cal.getTime()));
str.append(message+"\n");
}
This one is a part of my Java Serve code. BTW I am using TCP port to communicate my server and my client thru the same network. I want to save to a textfile the text that is holded by the str string. How can I do that? Or is that possible? Thanks in advance!
Kindly check out my code:
PrintWriter out= new PrintWriter(new BufferedWriter(new FileWriter("C:/foo.txt")));
while ((message = bufferedReader.readLine()) != null) {
System.out.println("Message from " + message + " at " + dateFormat.format(cal.getTime()));
str.append(message+"\n");
out.println(message);
}