Help, I'm slowly being driven mad trying to get round a problem.
I have a server and client that operate happily together by means of a simple protocol. Now I'm trying to get the server to write the clients reponses to a txt file, so I can do something with them later... However....The outfile is being generated, but its blank.
Post a little bit of code that does the writing and maybe we can spot something. Use the "Code" button below the editor window to keep your code formatting and make it easier for us to read.
Thanks for the reply Stan, thought it would be rude to just throw in loads of code without an introduction!! I've used the code button... I guess the error is on the outfile printwriter, but can I see it? The file is created, but nothing is written.
import java.net.*; import java.io.*;
public class libraryServer { public static FileOutputStream outStream; public static PrintWriter outFile; public static void main(String[] args) throws IOException {
ServerSocket serverSocket = null; try { serverSocket = new ServerSocket(4444); } catch (IOException e) { System.err.println("Could not listen on port: 4444."); System.exit(1); }
outStream= new FileOutputStream("hamish.txt"); outFile = new PrintWriter(clientSocket.getOutputStream(),true); BufferedReader in = new BufferedReader(new InputStreamReader( clientSocket.getInputStream()));
String inputLine, outputLine; libraryProtocol kkp = new libraryProtocol();
>Now I'm trying to get the server to write the clients reponses to a txt >file, so I can do something with them later... However....The outfile is >being generated, but its blank.
The only printwriter in your piece of code writes back to the client. from your code,
outFile = new PrintWriter(clientSocket.getOutputStream(),true);