getting stressed over Java's many methods of I/O. BufferedReader/writer, Printwriter , ObjectInputStream and all that Jazz! Why can't Java be more simple?
here's my problem. Trying to write a client/server as exercise. here's my code for server which accept the connection and write to file.
String inputLine;
while (true){
connection = server.accept();
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("foo.out")));
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((inputLine = in.readLine()) != null) {
out.write(inputLine);
}
out.close();
in.close();
connection.close();
}
At the client side: i am using this (sending a file over to server):
BufferedReader inPut =
new BufferedReader(new InputStreamReader( new FileInputStream(fileName) ));
PrintWriter output = new PrintWriter( client.getOutputStream(), true);
Although the file gets sent over, the file is corrupted. What is the most preferred method of I/O for sending over files through the network? Getting crazy over Java!