Corrupted JPEG: DataInput/OutputStream  
Author Message
Timo Nentwig





PostPosted: 2004-6-7 1:17:00 Top

java-programmer, Corrupted JPEG: DataInput/OutputStream Hi!

I download a JPG and write it to disk; this is rather old code which
certainly worked. The only thing I'm aware of that changed is JDK 1.4 ->
1.5b2. The written file is corrupt:

URL u = new URL ("http://foo/bar.jpg");
DataInputStream in = new DataInputStream
(u.openConnection().getInputStream());

File f = new File (foo);
FileOutputStream fs = new FileOutputStream (f);
DataOutputStream out = new DataOutputStream (fs);

for (int b; (b = in.read ()) != -1;)
{
out.write (b);
}

in.close();
fs.close();
out.close();


What's wrong? And, can I repair the corrupt files?