Hi,
I am using a tracking system which sends x, y and z coordinates over a socket. I want to store this information in a file to hopefully read back in later as seperate pieces of information, i.e the x coordinate, the y coordinate, the z coordinate. The x, y and z coordinates are updated every second so i need the file to update accordingly. So far I can get the information printing in my java shell but I am struggling with getting the information to print to a file. Any help would be greatly appreciated.
import java.io.*; import java.net.*; public class File { public static void main(String[] args) throws IOException { Socket kkSocket = null; PrintWriter out = null; BufferedReader in = null; try { kkSocket = new Socket("192.168.33.39", 12000); out = new PrintWriter(kkSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream())); } catch (UnknownHostException e) { System.err.println("Don't know about host: Adam."); System.exit(1); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to: Adam."); System.exit(1); } BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); String fromServer; String fromUser; while ((fromServer = in.readLine()) != null) { System.out.println("Server: " + fromServer); if (fromServer.equals("Bye.")) break; try{ // Create file FileWriter fstream = new FileWriter("outs.txt"); BufferedWriter outs = new BufferedWriter(fstream); outs.write("Server: " + fromServer); //Close the output stream outs.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } out.close(); in.close(); stdIn.close(); kkSocket.close(); } }