L
Louis
Hi all,
In fact, I am working on a http client assignment. Text file is ok,
but binary is failed (i try for a gif, but the image get distorted.
Original file size is the same to download one, but md5sum are
different.
Can anyone have a look on my code? Where goes wrong?
- What 'in' should I use? I need to 'readLn' for header and then
'read/readByte' for binary...
- What file output I need? I heard that FileWriter is not appropiate?
server = new Socket(url.getHost(), (url.getPort() == -1 ?
DEFAULTHTTPPORT : url.getPort()));
out = new PrintWriter(server.getOutputStream(), true);
in = new BufferedReader(new
InputStreamReader(server.getInputStream()));
..
..
..
tempfile = File.createTempFile(tempprefix, tempsuffix);
fw = new FileWriter(tempfile);
int c;
while ((c = in.read()) != -1) {
fw.write(c);
}
..
..
..
In fact, I am working on a http client assignment. Text file is ok,
but binary is failed (i try for a gif, but the image get distorted.
Original file size is the same to download one, but md5sum are
different.
Can anyone have a look on my code? Where goes wrong?
- What 'in' should I use? I need to 'readLn' for header and then
'read/readByte' for binary...
- What file output I need? I heard that FileWriter is not appropiate?
server = new Socket(url.getHost(), (url.getPort() == -1 ?
DEFAULTHTTPPORT : url.getPort()));
out = new PrintWriter(server.getOutputStream(), true);
in = new BufferedReader(new
InputStreamReader(server.getInputStream()));
..
..
..
tempfile = File.createTempFile(tempprefix, tempsuffix);
fw = new FileWriter(tempfile);
int c;
while ((c = in.read()) != -1) {
fw.write(c);
}
..
..
..