Как я могу сохранить результаты, полученные с сервера, в текстовый файл
Can anybody help me with this here. I am working on a network application where I have to create a socket connection to the IP address and port that they already given me and then send XML message to the socket and finally include the ReadMe.txt file where I will save what I have received from the server <pre>Send the following XML message to the socket, Please note there is no security, no certificates, just a plan TCP/IP connection. The request message is formatted below. Please include a README.txt file where you saved what you have received from the server. Without this file, your assignment will not be evaluated. <request> <EventType>Authentication</EventType> <event> <UserPin>12345</UserPin> <DeviceId>12345</DeviceId> <DeviceSer>ABCDE</DeviceSer> <DeviceVer>ABCDE</DeviceVer> <TransType>Users</TransType> </event> </request>
Что я уже пробовал:
private static Socket socket; public static void main(String args[]) { try { socket = new Socket( "196.37.22.179", 9011); //Send the message to the server //PrintStream outstrm = null; OutputStream os = socket.getOutputStream(); OutputStreamWriter osw = new OutputStreamWriter(os); BufferedWriter bw = new BufferedWriter(osw); String str; str = "<request>"; str += "<EventType>Authentication</EventType>"; str += "<event>"; str += "<UserPin>12345</UserPin>"; str += "<DeviceId>12345</DeviceId>"; str += "<DeviceSer>ABCDE</DeviceSer>"; str += "<DeviceVer>ABCDE</DeviceVer>"; str += "<TransType>Users</TransType>"; str += "</event></request>"; bw.write(str); bw.flush(); System.out.println("Message sent to the server......! "); //Get the return message from the server InputStream is = socket.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); } catch (Exception exception) { exception.printStackTrace(); } finally { //Closing the socket try { socket.close(); } catch(Exception e) { e.printStackTrace(); } } }
OriginalGriff
И что же?
В чем проблема?
Где ты застрял?
Какая помощь вам нужна?
Samkelo Siyabonga Ngubo
Я хочу почитать из README.txt файл для хранения результатов с сервера в файле
Kevin Marois
Посмотрите на StreamWriter