Corrupted JPEG: DataInput/OutputStream

T

Timo Nentwig

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top