The problem is that Readers/writers read text (as opposed to Input~/OutputStreams). FileReader internally uses the default operating system encoding. That conversion will never do for binary files. Also note, that readLine discards the line ending (\r\n
, \n
or \u0085
). As of Java 7 you can do
Files.copy(file.toPath(), socketOut);
instead of the wile loop.